problem with before :save and newly created objects
Reported by pchm | June 4th, 2008 @ 01:01 PM
After upgrading to 0.9.1, I've run into some problems with saving objects. It appears that if you define a 'before :save' callback and create a new object, DM somehow can't handle the callback properly and throws an exception.
class Article
include DataMapper::Resource
property :title, String
before :save do
# do something
end
end
@article = Article.new({:title => 'A sample article'})
@article.save # -> throws an exception
Exception details:
super: no superclass method `save' - (NoMethodError)
/usr/lib/ruby/gems/1.8/gems/dm-validations-0.9.1/lib/dm-validations.rb:35:in `save'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.1/lib/data_mapper/hook.rb:112:in `call'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.1/lib/data_mapper/hook.rb:112:in `save'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.1/lib/data_mapper/hook.rb:108:in `catch'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.9.1/lib/data_mapper/hook.rb:108:in `save'
When I changed before :save to before :create everything worked fine.
Comments and changes to this ticket
-
Brent Dillingham June 11th, 2008 @ 11:45 AM
I'm having this same issue. See my pastie:
I encountered it first by requiring both dm-validations and dm-timestamps. I eliminated dm-timestamps from the equation by creating a before :save filter that does the same thing it does.
A few good fellows in the #datamapper had me shuffle around the order in which dependencies are in Merb's config/init.rb, but to no avail. The most suggested order was this:
use_orm :datamapper
require 'dm-validations'
Those are the only two dependencies in my application at the moment.
-

Jox June 10th, 2008 @ 03:25 AM
You can temporarily circumvent this problem by defining
before :create before :updateinstead of
before :saveI had to do this with is-nested_set.
-
-
Michael Leung June 11th, 2008 @ 07:13 PM
I am having this issue as well. We just updated our OSS blog (featherblog.org) to DM 0.9.1 and when calling save on some models we also get: super: no superclass method `save' - (NoMethodError).
The thing is, I can't really see a clear pattern to it. I thought it might be what some of the other users reported in this ticket about the callbacks. So I changed them to before :create, :before and still received the error. Then I changed the order of:
include DataMapper::Resource
include DataMapper::Validate
To
include DataMapper::Validate
include DataMapper::Resource
And that worked. However in a model with no callbacks at all, and just an include to Resource we still get the error.
-
Michael Leung June 11th, 2008 @ 07:15 PM
Sorry I didn't mean before :create, :before, I meant before :create, and after :create.
-
Carl Lerche June 12th, 2008 @ 05:49 PM
I really believe that this is related to #371, which I fixed. So, if you can grab the latest master (dm-core AND dm-more), please test this again. If it still fails, please let me know.
-
Brent Dillingham June 14th, 2008 @ 01:51 PM
Sweet! Just confirmed that your fix does appear to have worked, Carl. Nicely done, and thanks.
-

pchm June 26th, 2008 @ 09:06 AM
- → Tag changed from to dm-more
Again, before and after hooks don't seem to work at all. Even the "before :update/:create fix" doesn't help...
-
Bernerd Schaefer August 1st, 2008 @ 09:54 AM
- → State changed from new to resolved
There has been major work done on fixing our hooks, so this should no longer be a problem.
-

cheba August 21st, 2008 @ 10:59 AM
In what revision it was fixed? It seems that in edge DM hooks does not work. At least I had no success with before :save and before :create.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
