Open OscarGodson opened 9 years ago
I'm not 100%, but I suspect this is going to be a matter of querying on eager loaded associations.
I'm imagining a many-to-many situation, where a Family has many MembershipModels, and so do Users.
A rough prototype of what I suspect would work is:
Family.all({
and:[
'membership.userId': firstUserId,
'membership.userId': secondUserId,
]
}, { includes: 'Membership'}, function (err, families) {
console.log("Families that have both members:");
console.dir(families);
});
I need a query that finds all the families that user1 and user2 are a part of (think of families as "groups") and where user1 is an admin and user2 is not. In SQL I'm able to do this with a self join and a
ON TRUE
. I was curious if this was possible with Geddy Model. I have the following:This gets all memberships for payee_id where their permission level is 0 OR where payer_id has a permission level of 1, but it doesn't find where they are in the same family. Is there anyway to do this? Here's the SQL: