tortoise / tortoise/tortoise-orm
Allow 'fetch_related', if given no arguments, to fetch every relationship.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Simple feature request that I would be willing to try to open PR for if idea is accepted. If fetch_related is not given any arguments it should fetch all of the relationships tied with that model.
from tortoise import models
class First(models.Model): ...
class Second(models.Model): ...
class Model(models.Model):
first = fields.ForeignKeyField("First", on_delete=fields.SET_NULL)
second = fields.ForeignKeyField("Second", on_delete=fields.SET_NULL)
Model.fetch_related()
# The above function call would behave as the function call below.
Model.fetch_related("first", "second")
Some might argue this is too implicit, and I would not argue. Perhaps a better option is a new function, fetch_all_related() that does the equivalent.
Model.fetch_all_related()
This would also include modifications to prefetch_related - whether with no arguments, or prefetch_all_related.
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 with the fetch_related and prefetch_related entry points and trace how relationship arguments are currently handled. Decide whether no-argument calls or new fetch_all_related and prefetch_all_related methods fit the API, including the implicitness concern. Done means all relationships on the model are fetched consistently and the chosen behavior is covered for both APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100