Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Automatic validation on has_many should not be performed twice

#483

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?

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

State: resolved
Milestone: none
Assigned to: DHH DHH
Importance: none

Activity

  1. Jan De Poorter
    Jan De Poorter
    • 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 ;-)

    June 25th, 2008 @ 11:51 AM

  2. Tarmo Tänav
    Tarmo Tänav
    • 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.

    September 18th, 2008 @ 08:10 AM