我不明白在哪种情况下我应该使用 :include 选项而不是 :through 选项?
例如,我可以这样编写模型:
Class Customer < ActiveRecord::Base
has_many :orders, :include => :line_items
end
class Order < Active Record::Base
belongs_to :customer
has_many :line_items
end
class LineItem < ActiveRecord::Base
belongs_to :order
end
或者我可以这样写:
Class Customer < ActiveRecord::Base
has_many :orders
has_many :lineitems, :through => :orders
end
class Order < Active Record::Base
belongs_to :customer
has_many :line_items
end
class LineItem < ActiveRecord::Base
belongs_to :order
end
感谢澄清什么练习匹配哪个选项。