#1435 ✓not-applicable
Kalpesh Patel

Conditional Validations not working when used in Discriminator Class

Reported by Kalpesh Patel | October 20th, 2010 @ 04:43 AM

class Account

include DataMapper::Resource

property :id,  Serial
property :name, String
property :balance, Integer
property :min_balance, Integer
property :type,  Discriminator

end

class CurrentAccount < Account

validates_with_block :balance, if => lambda { |a| a.min_balance} do
    balance > min_balance  #validation block
end

end

In the above example :if block invoked after invoking actual validation. :if block should be called first and if its true than only validation block should be invoked.

Above example works fine if I replace validates_with_block with validates_with_method and move my validation logic to a method.

Comments and changes to this ticket

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) October 24th, 2010 @ 11:30 AM

    • State changed from “new” to “not-applicable”
    • Assigned user set to “Martin Gamsjaeger (snusnu)”

    I couldn't reproduce the error you get. I also noted that the code you've pasted above actually contains a syntax error. It's supposed to be :if => ... and not if => ....

    Here's the standalone script i used to reproduce: http://pastie.org/1245200

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 »

Pages