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.

cleanup and speedup of validates_associated

#1686

This is a tiny patch to improve the readability and performance of #validates_associated in ActiveRecord. The obscure use of #inject is replaces by #collect and #all?, using #collect to preserve the semantics of testing every record for validity by preventing early termination of the #all? loop. This is not only more readable, but about 40% faster too.

I wanted to replace the ternary operator that tests whether the value is an Array with the Array() coercion method, but that didn't work well with the association proxy, so that bit of ugliness remains.

Reported by Josh Susser · January 2nd, 2009 @ 05:41 AM

State: committed
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Repository
    Repository
    • State changed from new to committed
    • Tag set to activerecord, optimisation, tiny, validates_associated

    (from [ccda96093a3bf3fb360f7c6d61bbbf341b2ae034]) Minor refactoring of validates_associated to replace #inject with #collect + #all?

    [#1686 cleanup and speedup of validates_associated state:committed] http://github.com/rails/rails/co...

    January 22nd, 2009 @ 12:45 AM