User
and Organization
have a many-to-many association through Relationship
.
One of the variables in the Relationship
model is a boolean called member
.
A user
can occur in the Relationship
model multiple times as a user
can be related to multiple organizations
.
How can I select a random instance from all the users
that 1) don't have a relationship with any organization
(so don't occur in the Relationship
model) plus 2) those users
that do have a relationship with an organization but for whom member = false
for all their relationships with organizations?
I was thinking of something like:
user = User.where( relationship_id = nil || ??? ).offset(rand(0..100)).first