RoR: NoMethodError when executing delete_all for a has_many relationship

后端 未结 5 1925
眼角桃花
眼角桃花 2021-01-22 18:01

My classes are as follows, with Customer inheriting from User using the single-table inheritance approach. User has attributes name and email while Order has destination.

<
5条回答
  •  旧时难觅i
    2021-01-22 18:09

    It seems you have no inverse associations and Rails fails to resolve the order's customer when updating the cached counters. Try this:

    class Customer < User
      has_many :orders, inverse_of: :customer
    end
    
    class Order < ActiveRecord::Base
      belongs_to :customer, inverse_of: :orders
    end
    

提交回复
热议问题