This project is archived and is in readonly mode.

#2545 ✓wontfix
Amos King

validations based on methods and not actual attributes

Reported by Amos King | April 22nd, 2009 @ 11:43 PM | in 2.x

The validations are calling methods. Let's say I have an attribute 'attr' and I have a validates_presence_of :attr. Now I have the following method

def attr super || 0 end

This is a dumb example, but I think you will get the point.

MyObject.create!

does not fail. This is because the validations are running against methods and not against actual attribute values.

Comments and changes to this ticket

  • Max Lapshin

    Max Lapshin April 23rd, 2009 @ 10:22 AM

    • Tag set to invalid

    It is ok, because You've defined accessor method yourself.

  • Amos King

    Amos King April 23rd, 2009 @ 01:25 PM

    • Tag changed from invalid to validations

    It is not ok. If your database isn't constraining that column you may have bad data in the database.

  • CancelProfileIsBroken

    CancelProfileIsBroken April 23rd, 2009 @ 01:47 PM

    • State changed from “new” to “wontfix”

    If you have a fix for this, please submit a patch. Otherwise, it looks like a simple case of "don't do that." If you patch, please explain how Rails is supposed to figure out what database column you intend to be validated for an arbitrary method.

  • Amos King

    Amos King April 23rd, 2009 @ 03:18 PM

    Rails should validate off of the attribute and save from the attribute. I'm not suggesting to change the save. The save currently works off of the attributes. I'm suggesting that since save is run from those attributes that validations should also be run against the same attributes.

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages