我有以下型号:Rails的activerecords嵌套包括
class BusinessProcess < ActiveRecord::Base
has_many :todos
end
class Todo < ActiveRecord::Base
has_one :row
end
class Row < ActiveRecord::Base
has_many :users
end
我怎么能算的rows
在BusinessProcess
具有对特定user
行数?
是这样的:
@businessProcess.todos.includes(XXX).where(users.id=?,1).count
请问您可以添加ActiveRecord类的代码吗?至少是协会。顺便说一下* @processProcess *不是很Rubyish。 –
我一直在看你的问题。你能澄清一件事吗?在'Row'中,你有'has_many:users'。这意味着,我认为'User'应该有一个'belongs_to:row'。那么看起来像'User'只能有一个'Row'。它是否正确?看起来很奇怪,因为'User'可能会有很多行,在这种情况下,您需要一个多对多的连接模型。谢谢。 – jvillian