orm icon indicating copy to clipboard operation
orm copied to clipboard

Add ability to query pivot columns in many to many relationship.

Open yubarajshrestha opened this issue 4 years ago • 0 comments

Describe the feature as you'd like to see it There are situations where you might want to filter certain conditions in pivot table in-case of many-to-many relationships. There doesn't seems to have this feature in ORM.

What do we currently have to do now? We have to actually add that feature. The idea is as below:

class User(Model):
    __table__ = "users"

class Role(Model):
    __table__ = "roles"
    @belongs_to_many
    def users(self):
        return User.where_pivot("approved", True)

# imagine there's a pivot table `role_user` with following schema
with self.schema.create('role_user') as table:
            table.unsigned_integer("role_id")
            table.unsigned_integer("user_id")
            table.boolean("approved").default(False)
  • [x] This doesn't seems to be a breaking change, this should just add one extra feature

yubarajshrestha avatar Mar 19 '22 07:03 yubarajshrestha