
parent.children.destroy! bypass the child's before :destry hook
Reported by zhhz | February 11th, 2009 @ 10:39 AM
I am not sure if this is the feature, it is designed to do so, or I'm doing it wrong. Here is situation I have:
version: 0.9.9
class Order before :destry, :destroy_items .... has n, items
def destroy_items
# this by pass the items before destroy
items.destroy!
# this part is working, the :check_xxx is called
items.each |item| do
...
item.destroy
end
end end
class OrderLineItem ... before :destroy, :check_xxx
belongs_to :order
def check_xxx
raise "the_error_message" if xxxxx
end
end
Comments and changes to this ticket
-
zhhz February 11th, 2009 @ 10:40 AM
Sorry, the format is bad. Here is the code from gist http://gist.github.com/62107.js
-
zhhz February 11th, 2009 @ 10:45 AM
Again, the link on gist: http://gist.github.com/62107
NOTE: I've not tried the dm-constraints, so correct me if I'm wrong, but it seems like the same. Here is code link: http://gist.github.com/62113
-
Cyril Mougel February 11th, 2009 @ 11:43 AM
- Tag changed from 0.9.9, destroy! to destroy!, hook
It's normal that hook doesn't work. But I think a :destroy! hook are welcome.
-
Dan Kubb (dkubb) February 21st, 2009 @ 12:40 AM
- State changed from unconfirmed to not-applicable
The Collection#destroy! method is actually supposed to bypass all hooks. The way you're doing it by looping over the records and calling each Resource#destroy method is the proper approach to execute each Resources' hooks.
In dm-core 0.10.0 there will be a Collection#destroy method that wraps this up and essentially does the same thing.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »