Many-to-Many Operations — Aquilia Documentation
Comprehensive guide and documentation for Many-to-Many Operations in the Aquilia framework. View API reference, examples, and implementation patterns.
Docs / Models / ManyToMany Operations ManyToMany Operations Working with junction tables, attaching and detaching relations, and defining custom through models. Attaching and Detaching Manage relations on a saved model instance using the attach() and detach() methods: # Add a tag (ID 3) to an article instance await article.attach(db, "tags", [3]) # Remove tag (ID 3) from the article await article.detach(db, "tags", [3]) # Clear all tags await article.detach(db, "tags") Custom through Models When you need additional metadata columns on the junction table, declare a custom model class and pass it to the through argument: class User(Model): table = "users" groups = ManyToManyField("Group", through="Membership") class Group(Model): table = "groups" class Membership(Model): table = "memberships" user = ForeignKey(User, on_delete="CASCADE") group = ForeignKey(Group, on_delete="CASCADE") role = CharField(max_length=50) joined_at = DateTimeField(auto_now_add=True) Hydration Primitives Transactions )
Go to Homepage