#1509 new
agate

Validation should be execute after before_create | before_update | before_save hooks

Reported by agate | May 6th, 2011 @ 01:58 AM

Hi Dear DataMapper Developers,

I am using data_mapper ORM for my new project. I found a weird behavior in this framework --- The validations will be executed before the before hooks.

For instance:
I have a model with UUID key

class User
  property :id, String, :key => true
  property :name, String, :required => true

  before :create, :set_uuid_to_id

  private
  def set_uuid_to_id
    self.id = MyUUIDGenerator.gen
  end
end

So when I try to run:

u = User.new(:name => 'hao')
u.save

It will return false(Because id is key and it can not be blank. So validation will fail)

I digged in sourcecode. I found dm-validations will execute the validations before these hooks.
So the workflow now is:

  • validate
  • before stuff
  • save
  • after stuff

But I think the correct workflow should be:

  • before stuff
  • validate
  • save
  • after stuff

What do you think?

Thanks,
Hao.

No comments found

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages