# Parent model running validations on all existing children when using accepts\_nested\_attributes\_for

**URL:** <https://www.ruby-forum.com/t/parent-model-running-validations-on-all-existing-children-when-using-accepts-nested-attributes-for/190717>\
**Category:** Rails\
**Created:** [June 25, 2010, 6:30pm UTC](https://www.ruby-forum.com/t/parent-model-running-validations-on-all-existing-children-when-using-accepts-nested-attributes-for/190717 "2010-06-25T18:30:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubenrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9a140/32.png) [@rubenrails](https://www.ruby-forum.com/u/rubenrails)\
**Post date:** [June 25, 2010, 6:30pm UTC](https://www.ruby-forum.com/t/parent-model-running-validations-on-all-existing-children-when-using-accepts-nested-attributes-for/190717/1 "2010-06-25T18:30:13Z")

</div>

In my application, a Language has many Phrases. I’m using  
accepts\_nested\_attributes\_for, so by updating the parent I also save  
changes to associated phrases. Here my models:

class Language \< ActiveRecord::Base  
has\_many :phrases  
accepts\_nested\_attributes\_for :phrases  
end

class Phrase \< ActiveRecord::Base  
validates\_presence\_of :value  
belongs\_to :language  
def before\_validation  
print “\nValidating: #{self.value}\n”  
end  
end

I was expecting Rails to only validate the phrase that is being  
updated, here you can see it’s validating all of the existing phrases:

$ script/console  
Loading development environment (Rails 2.3.5)

> > lang = Language.first  
> > =\> #\<Language id: 1, name: “Italiano”\>
> 
> > lang.phrases  
> > =\> [#\<Phrase id: 7, value: “Buona notte”, language\_id: 1\>,  
> > #\<Phrase id: 10, value: “Ciao”, language\_id: 1\>,  
> > #\<Phrase id: 11, value: “Prego”, language\_id: 1\>]

> > lang.phrases\_attributes = [{:id =\> “7”, :value =\> “Buon giorno”}]  
> > =\> [{:value=\>“Buon giorno”, :id=\>“7”}]
> 
> > lang.save

Validating: Buon giorno

Validating: Ciao

Validating: Prego

=\> true

Validating all phrases is a real problem in my app, as I have tens of  
thousands; Is there a way to avoid this? Is this normal behavior for  
Rails?
