Closed Triquetra closed 3 years ago
@Triquetra you can reach the same result in different ways.
In case you have the organization record:
org = Organization.get(name="X")
admin_users = org.users.switch(Membership).where(lambda m: m.role == "admin").select()
or without switch
:
admin_users = org.users.where(Membership.role == "admin").select()
with a single query using switch
:
admin_users = User.all().join('organizations').switch(Organization).where(
lambda o: o.name == "X"
).switch(Membership).where(
lambda m: m.role == "admin"
).select()
with a single explicit query:
User.all().join('organizations').where(
(Organization.name == "X") & (Membership.role == "admin")
).select()
Given the following Models:
How would one get a list of User records with membership at Organization X and role == 'admin'?
The documentations talks about how to add a record with a role on the join table, but I can't figure out how to access the join table data from the User records.