I follow the Railscast tip on creating a different relationship model many-to-many. However, I am having problems retrieving transitive relationship data.
Imagine there are 3 many-to-many models: User <-> Color <-> Shades
I made two more models:
ColorLiking (maintains User <-> Color), DiffShades (maintains Color <-> Shades)
Question
Now, if everything is set up correctly ... how to find Shadeswhich belong User?
How to set up this relationship?
class User < ActiveRecord::Base
has_many :shades, :through=>:diffShades, :source => :color
end
doesn't seem to work ...
Using SQL, the query below will work:
select * from shades
where id in (select shade_id from diffshades
where color_id in (select color_id from colorlikings
where user_id = ?))
source
share