ruby on rails - Find objects through objects -
a post belongs discussion, discussion belongs forum.
say have forum object:
forum #=> <forum:#>
from it, how should return posts belong forum's discussions? easy enough return discussions belong forum, not posts that, through discussions, belong forum.
(btw i'm not building forum example)
to second level can use has_many :through example:
class discussion < activerecord::base has_many :posts end class forum < activerecord::base has_many :discussions has_many :posts, through: :discussions end # posts in discussions in forum. forum.find(1).posts
Comments
Post a Comment