datamapper / dm-rails

Integrate DataMapper with Rails 3
http://datamapper.org/
MIT License
175 stars 39 forks source link

before :save and before :create hooks are not working #31

Closed jaischeema closed 12 years ago

jaischeema commented 12 years ago

I am using dm-rails version 1.2.0 with dm-core version 1.2.0 and rails version 3.1.3.

In my model, when I define before :valid? or before :destroy, they work without any problem but before :save or before :create does not work.

Please let me know what else do I need to submit to this issue.

solnic commented 12 years ago

Can you show an example where it doesn't work?

jaischeema commented 12 years ago

In this model, https://github.com/jaischeema/doorkeeper/blob/datamapper/app/models/application.rb, in place of before:valid?, I was using before :create.

I also removed the generate methods from within the block and tried to use a simple put "in the hook, but it doesn't do anything.

solnic commented 12 years ago

before :create/:save hook won't be called if a resource is not valid, this is why in this case you need to do before :valid? and it's ok

jaischeema commented 12 years ago

oh, I didnt knew that was the expected behaviour and was going by ActiveRecord sort of workflow. Thank you for your time.