在预加载时,反向加载不起作用,为什么?

gywdnpxw  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(286)

鉴于以下情况:

class Ns::Collection < ActiveRecord::Base
  has_many    :products, foreign_key: :ns_order_id , inverse_of: :collection
end

class NS::Product < ActiveRecord::Base
  belongs_to  :collection, foreign_key: :ns_order_id, inverse_of: :products
end

有人能解释为什么以下结果为真:

a = Ns::Collection.first
b = a.products[0]
a.code == b.collection.code
a.code = 'Something'
a.code == b.collection.code

但当我尝试预加载时,它返回false:

a = Ns::Collection.includes(:products).first
b = a.products[0]
a.code == b.collection.code
a.code = 'Something'
a.code == b.collection.code

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题