Open aarondufall opened 2 years ago
Got the same error.
I think it's probably because of this line:
belongs_to tenant, **valid_options
It doesn't have any has_many association, only belongs_to
Any updates? Is #307 going to be approved any time soon?
@aarondufall
actually you can do this way
# AccountUser.rb
def self.users
user_ids = self.all.pluck(:user_id).uniq
User.unscoped.where(id: user_ids)
end
# User
default_scope { AccountUser.users }
many to many relation ship and reuse the default scope of child model to do it. don't forget unscoped
of the original model
I followed the example of the Has and belongs to many. What I was expecting to happen is that when the following code is run, it would scope by the association.
The idea being the user could belong to many accounts but would only be found if the
current_tenant
was an account it was a member of.When I run the above code the query it looks for an
account_id
on theUser
model. Producing an error when it can't find the foreign key.This is what I expected as the normal behaviour for
acts_as_tenant :account
. I thought adding thethrough:
option would then allow for the user to belong to many accounts, but only return the one that is the current tenant.What exactly does the
through:
option allows for? Is there a common approach or best practice for a user belonging to many tenants?Here is the code I used for the models