私はモデルに従う必要があります
User
has_many :threads
....
Thread
belongs_to :user
has_many :posts
....
Post
belongs_to :thread
....
ユーザーからすべてのスレッドを取得するには、ユーザーUser.find( params[:id]).threads
からすべての投稿を取得するにはどうすればよいですか?
私はモデルに従う必要があります
User
has_many :threads
....
Thread
belongs_to :user
has_many :posts
....
Post
belongs_to :thread
....
ユーザーからすべてのスレッドを取得するには、ユーザーUser.find( params[:id]).threads
からすべての投稿を取得するにはどうすればよいですか?
class User
has_many :threads
has_many :posts, :through => :threads
end
User.find(params[:id]).posts
私が今朝大騒ぎしていない限り、トリックを行う必要があります。
User
has_many :threads
has_many :posts, :through => :threads
....
Thread
belongs_to :user
has_many :posts
....
Post
belongs_to :thread
次に、次のことができるはずです。
user = User.first
user.posts