ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association

后端 未结 3 1399
小鲜肉
小鲜肉 2021-01-04 12:57
class Transaction < ActiveRecord::Base
  belongs_to :account, :polymorphic => true
end

class Bankaccount < ActiveRecord::Base
  has_many :transactions, :as         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 13:30

    For those that got this error even when they aren't trying to query conditions on the polymorphic association, it's because includes decided to call eager_load when polymorphic associations are only supported by preload. It's in the documentation here: http://api.rubyonrails.org/v5.1/classes/ActiveRecord/EagerLoadPolymorphicError.html

    So you should always use preload for polymorphic associations.

提交回复
热议问题