Feb 13, 2009

DataMapper destroy! hook

I was working on a project this week, I just found out, in DM association, parent.children.destroy! bypasses the child's before :destry hook, here is example:


I also noticed that there is a plugin dm-constraints, I haven't check it out yet, but it seems like the same, here is the code from the plugin:


I filed an issue report on lighthouseapp.com.

UPDATE(Feb-21-2009): Just got the note from Dan Kubb( one of the core DM developers):
"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."

This makes a lot of sense. Like always, I really appreciate the attitude of the developers from DM, that is one one the reason I am using DM.

No comments: