After a bit more digging, I read in the documentation that the
Resource::save! method "bypasses hooks". I'm guessing hooks includes
callbacks, which would be what dm-timestamps is using to initalize the
created_on property.

I was under the assumption that Resource::create! and Resource:: save!
worked like ActiveRecord, where it was just a simple wrapper around
save that would throw an exception if the validation failed. If this
is the case, I can't imagine ever wanting to use them, but maybe a
save! method that bypasses these hooks are useful to someone.

What's a good substitute to get the standard activerecord behavior for
"create!" and "save!"?


On Sep 25, 12:26 am, Jacques Crocker <[email protected]> wrote:
> Having some major issues with dm-timestamps in dm-more 0.10.0. When I
> use model.save!, it throws validation errors since the created_on
> isn't being set. I traced the problem to the fact that dm-timestamps
> uses a before filter on :save
>
>     def self.included(model)
>       model.before :save, :set_timestamps_on_save
>       model.extend ClassMethods
>     end
>
> in order to initialize the timestamps.
>
> Shouldn't before :save callbacks also be activated with save! is run?
> before :save seems like a pretty common callback, and if they don't
> get run when using save!, that seems like a bit of a problem.
>
> Maybe the solution is to have save! just callback to save. We'll have
> to refactor a bit to handle the save_parents, save_children, and
> save_self with the safe option.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to