destroy dependent data without destroying original record in rails -
is there easy way destroy data associated particular record, without destroying original record. example, if have
class user < activerecord::base has_many: pets, dependent: :destroy has_many: houses, dependent: :destroy end class pet < activerecord::base belongs_to :user end class house < activerecord::base belongs_to :user end
if wanted delete user , pets , houses, like:
user = user.first user.destroy
but if want keep user, want delete pets , houses? there easy way that?
you have manually, callback example.
class user {callback} :destroy_pets private def destroy_pets self.pets.delete_all end end
wiki
Comments
Post a Comment