This project is archived and is in readonly mode.

#483 ✓resolved

Automatic validation on has_many should not be performed twice

Reported by wildchild | June 25th, 2008 @ 10:51 AM

I found that has_many performs automatic validation of associated records and if "validates_associated" declared then validation performed twice.

This is very painful if different error message needed (eg. other language), also this behavior will produce many similar error messages if more then 1 associated records are invalid (don't think that it's useful).

I see different ways to workaround:

1) Check that associated object already validated (new property needed)

2) Check that validates_associated performed (don't know how to check this)

3) Check for record.errors.any? before calling record.valid? but for valid records validation will be performed again (possible overhead for complicated validations)

Any ideas, guys?

Comments and changes to this ticket

  • Jan De Poorter

    Jan De Poorter June 25th, 2008 @ 11:51 AM

    • Tag set to activerecord, bug, has_many

    As discussed on IRC, you can use

    has_many :things, :validate => false

    and then add the validation, or least you will be able to do this once this patch makes it into core ;-)

  • Tarmo Tänav

    Tarmo Tänav September 18th, 2008 @ 08:10 AM

    • State changed from “new” to “resolved”
    • Tag changed from activerecord, bug, has_many to activerecord, bug, has_many

    As already pointed out, ":validate => false" can now be used to counter this problem.

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=""></a>