-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
When performing a collection.clear on an habtm relation it ends up deleting the objects themselves instead of just the ids in the arrays. delete_all and destroy_all exhibit the exact same behaviour as clear.
I put together a quick little gist to illustrate the issue.
https://gist.github.com/1025311
I'm thinking that this is maybe the desired behaviour? It's not the way AR handles it though and the Mongoid docs are a little unclear on the subject to me at least. (http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_and_belongs_to_many)
What's interesting is that if I instead assign an empty array to clear the association it works as expected and only removes the associations without deleting the associated object. Using .nullify on the collection works as expected as well.
In the Mongoid docs it looks like the desired behaviour for all clear, delete_all, and =[] should be the same.
http://mongoid.org/docs/relations/referenced/n-n.html