tortoise / tortoise/tortoise-orm
Ability to disable backward relation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
I think a lot of times you just don't need the backward relation, which is now automatically created by Tortoise. It can be a problem, when you have multiple interpretation for the same model. E.g. a user can be referenced multiple times, but never want to use it backwards.
Describe the solution you'd like
I have 2 solution proposals. Either or both would be good.
- You can give
related_nameparameter asFalseor empty string (I prefer False):
user: fields.OneToOneRelation['User'] = fields.OneToOneField('models.User', related_name=False, null=True)
- Only you use the backward relation if you specify it in the other side with annotation. In modern Python it would be a good solution. Without it IDEs can't know that property exists.
Additional context
I have this problem in my PR #260 . If you don't agree with this request, I still need to know somehow from backward_*_fields, which field has annotation at the other end. It could be described in a new property called e.g. annotated.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing PR #260 and the existing backward_*_fields behavior described in the issue. Determine which proposal is accepted for disabling or annotating backward relations; done means the chosen behavior and its handling of related_name are clearly defined and verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100