我必须遵循模型
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