I'm following Railscast Advice of making a different model to maintain many-to-many
relationships. However, I am having trouble extracting transitive relation data.
Imagine that there are 3 models with many-to-many: User <-> Color <-> Shades
I've made 2 more models:
ColorLiking (maintains User <-> Color), DiffShades (maintains Color <-> Shades)
Question
Now, If everything is set up correctly...how do I find the Shades
that belong to a User
?
How Will I setup that relationship?
class User < ActiveRecord::Base
has_many :shades, :through=>:diffShades, :source => :color
end
above does not seem to work...
Using SQL the below query would work:
select * from shades
where id in (select shade_id from diffshades
where color_id in (select color_id from colorlikings
where user_id = ?))