In object model, I have
has_many :likes
has_many :hates
has_many :users, :through => :likes
has_many :users, :through => :hates
How do I get the list of users for likes? E.g. object.users <--- but how do I specify through likes or hates?
You need to give these two different associations different names. What about
has_many :likes
has_many :hates
has_many :likers, :through => :likes, :source => :user
has_many :haters, :through => :hates, :source => :user
It seems that I need to add source too. If not Rails will be looking for likers/liker in likes.
has_many :likes
has_many :hates
has_many :likers, :through => :likes, :class_name => 'User', :source => 'user'
has_many :haters, :through => :hates, :class_name => 'User', :source => 'user'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With