RoR: NoMethodError when executing delete_all for a has_many relationship

后端 未结 5 1977
眼角桃花
眼角桃花 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条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-22 18:27

    Try updating you Customer class association with

    has_many :orders, :dependent => :destroy
    

    or

    has_many :orders, :dependent => :delete_all
    

    Depending on what you want to achieve.

    :destroy causes all the associated objects to also be destroyed.

    :delete_all causes all the associated objects to be deleted directly from the database without executing callbacks.

提交回复
热议问题