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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -