Delete Rails model and its associations in one action? NEWBIE question
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.
精彩评论