Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Error with has_and_belongs_to_many association #6
Note that when I put the acts_as_tenant(:account) before the :has_and_belongs_to_many association, the problem doesn't occur. But when I put it below the :has_and_belongs_to_many association in the model. The problem occurs.
The reason that I want to put it below the :has_and_belongs_to_many association is that I want to make an inheritance of the model and the child model will be assigned to acts_as_tenant. So, the code in the parent model will be executed first and following by the child model code.
Could you tell me how to solve this problem? Thank you in advance.
Thank you for replying me. Here are my models.
class Account < ActiveRecord::Base
class User < ActiveRecord::Base
class Role < ActiveRecord::Base
class Member < User
I have tracked to the code and the error comes from the model_extensions.rb.
71 reflect_on_all_associations.each do |a|
I think in this block code, it passes through the "unless" block because the association is HABTM and it gets an error in the "validates_each" block.
Right now, my code is changed. I decided to remove the roles table from my project and use the role_mask attributes instead.
Note that... If I add "|| a.macro == :has_and_belongs_to_many" to the line 72. It can solve the problem too. But I am not sure whether it affects the security? or am I doing the right thing.
Note2. in the error it said "undefined method user_id". So, I don't that why it involves with user_id.
@torsakch I think it's actually a problem with the gem: the gem currently assumes that every association will always be scoped to the tenant. In practice, a scoped model can be associated with a non-scoped model (like in your case).
I will need to fix this in the code. I'll try to push out an update tonight.