Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
yubarajshrestha opened this issue Mar 19, 2022 · 1 comment
Closed
1 task done
Labels
enhancement A feature that exists, works as intended but needs to be improved

Comments

@yubarajshrestha
Copy link
Contributor

yubarajshrestha commented Mar 19, 2022

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)
  • This doesn't seems to be a breaking change, this should just add one extra feature
@yubarajshrestha yubarajshrestha added the enhancement A feature that exists, works as intended but needs to be improved label Mar 19, 2022
@tara-ai tara-ai bot changed the title Add ability to query pivot columns in many to many relationship. Add ability to query pivot columns in many to many relationship. [enhancement](https://app.tara.ai/8/*/tasks/masonite-x-inc) #p Jul 2, 2022
@tara-ai tara-ai bot changed the title Add ability to query pivot columns in many to many relationship. [enhancement](https://app.tara.ai/8/*/tasks/masonite-x-inc) #p Add ability to query pivot columns in many to many relationship. [enhancement](https://app.tara.ai/8/*/tasks/masonite-x-inc) [P2](https://app.tara.ai/8/*/tasks/masonite-x-inc) Jul 2, 2022
@josephmancuso josephmancuso changed the title Add ability to query pivot columns in many to many relationship. [enhancement](https://app.tara.ai/8/*/tasks/masonite-x-inc) [P2](https://app.tara.ai/8/*/tasks/masonite-x-inc) Add ability to query pivot columns in many to many relationship. Jul 4, 2022
@josephmancuso
Copy link
Member

Pretty sure we can just do Model.where("role_user.approved", True) since belongs to many is doing a join. If thats not a good a solution we can reopen this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature that exists, works as intended but needs to be improved
Projects
None yet
Development

No branches or pull requests

2 participants