Jak*_*old 4 activerecord ruby-on-rails
说我有这些模型
class Project < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :project
belongs_to :user
end
class User < ActiveRecord::Base
has_many :comments
end
Run Code Online (Sandbox Code Playgroud)
这样我才能做到
p = Project.find(1, :include => :comments)
p.comments.collect(&:user).collect(&:name) # this executes select for each user
Run Code Online (Sandbox Code Playgroud)
我怎么说我还想包括评论的用户?
| 归档时间: |
|
| 查看次数: |
2547 次 |
| 最近记录: |