tortoise / tortoise/tortoise-orm
ManyToMany between three tables
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Is there a way to allow for many to many relation between three tables in Tortoise ORM, or I have to create an extra table to capture this.
basically a user can have a certain role over a certain fields and another over another set of fields:
class Users(Model):
id = IntField(pk=True)
name_first = CharField(max_length=255, null=False)
name_last = CharField(max_length=255, null=False)
username = CharField(max_length=255, null=False)
mail = CharField(max_length=255, null=False)
roles: ManyToManyRelation["Roles"] = ManyToManyField(
"models.Roles", related_name="users", through="user_roles_fields"
)
fields: ManyToManyRelation["Fields"] = ManyToManyField(
"models.Fields", related_name="users", through="user_roles_fields"
)
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 ManyToManyField declarations and the shared through value shown in the issue. Review the ORM's relationship behavior to determine whether one relation can connect users, roles, and fields, or whether a separate association model is required. Done means the supported modeling approach is established and covered by an appropriate example or test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100