Rails, Deleting Children without Deleting Parent using :has_many
Posted
by Dex
on Stack Overflow
See other posts from Stack Overflow
or by Dex
Published on 2010-04-20T07:04:55Z
Indexed on
2010/04/20
7:13 UTC
Read the original article
Hit count: 350
I have a model called MyContainer, which :has_many MyObjects.
I want to delete all the MyObjects in the container without having to delete the MyContainer. My model does have :dependent => :destroy, however I don't want to have to delete and re-create the object because it is slower.
Something like this does not work:
@obj = MyContainer.find_by_id(10) @obj.my_objects.delete_all
How can I accomplish this?
© Stack Overflow or respective owner