开发者

Delete Rails model and its associations in one action? NEWBIE question

开发者 https://www.devze.com 2023-03-08 13:09 出处:网络
I have a really simple association with the Devise user object where each user has one Profile (with more application specific stuff...)I am having no issues creating the User object and accessing the

I have a really simple association with the Devise user object where each user has one Profile (with more application specific stuff...) I am having no issues creating the User object and accessing the user and its profile object. i.e., @user.profile

However, I'm having an issues when I try to delete the profile object - I'd assume that when I delete the User object, it would also delete each associated object. The association in my User object is like so accepts_nested_attributes_for :profile, :al开发者_如何学运维low_destroy => true

The has_one and belongs_to associations are set on both the User and Profile objects. Maybe the issues is in Devise code - I'm stumped. An idea what I'm missing here.


You need to specify :dependent on the association:

has_one :profile, :dependent => :destroy

Look Association for more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消