【发布时间】:2014-09-15 09:31:44
【问题描述】:
我有以下关联。
class Farm < ActiveRecord::Base
has_many :crops
end
class Crop < ActiveRecord::Base
belongs_to :farm
has_many :seed_batches
end
class SeedBatch < ActiveRecord::Base
belongs_to :crop
has_many :tasks, through: :task_batches
end
class Task < ActiveRecord::Base
has_many :seed_batches, through: :task_batches
end
class TaskBatch < ActiveRecord::Base
belongs_to :task
belongs_to :seed_batch
end
本质上,一个农场有很多作物。每种作物都有许多种子批次。每个种子批次都有许多任务。
我的问题是:如何知道农场的 id 来完成所有任务?
我尝试了很多方法来进行 .where() 搜索,但都出现了错误。哪位大神可以赐教一下?
【问题讨论】:
标签: ruby-on-rails ruby activerecord associations where