# Validation Through Multiple Models from one Form

**URL:** <https://www.ruby-forum.com/t/validation-through-multiple-models-from-one-form/107438>\
**Category:** Rails\
**Created:** [June 21, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/validation-through-multiple-models-from-one-form/107438 "2007-06-21T21:04:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![freewolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@freewolf](https://www.ruby-forum.com/u/freewolf)\
**Post date:** [June 21, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/validation-through-multiple-models-from-one-form/107438/1 "2007-06-21T21:04:38Z")

</div>

Hey All,

I have a form that submits data to multiple models.

I have

class Man \< ActiveRecord::Base  
has\_many :notes  
has\_many :contacts

```
    validates_associated :contacts, :notes

```

validates\_presence\_of :first\_name  
validates\_presence\_of :last\_name

class Contact \< ActiveRecord::Base  
belongs\_to :man

```
    validates_presence_of :contact_info

```

class Note \< ActiveRecord::Base  
belongs\_to :man

```
    validates_presence_of :notes

```

However when I submit the form blank, it will only validate for the Man  
model. Not the other two. If I fill in the form then the data gets  
submitted to the DB tables just fine, it just will not validate more  
than that base model.

What am I missing??

Blessed Be

Phillip

---

<div class="post-metadata">

**Author:** ![freewolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@freewolf](https://www.ruby-forum.com/u/freewolf)\
**Post date:** [June 23, 2007, 9:19am UTC](https://www.ruby-forum.com/t/validation-through-multiple-models-from-one-form/107438/2 "2007-06-23T09:19:23Z")

</div>

On 6/21/07, Phillip B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> has\_many :contacts  
> class Note \< ActiveRecord::Base  
> belongs\_to :man
> 
> ```
> validates_presence_of :notes
> 
> ```
> 
> However when I submit the form blank, it will only validate for the Man  
> model. Not the other two. If I fill in the form then the data gets  
> submitted to the DB tables just fine, it just will not validate more  
> than that base model.

From: \<  
[http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000948](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000948)

> 

"NOTE: This validation will not fail if the association hasn’EURO~t been  
assigned. If you want to ensure that the association is both present and  
guaranteed to be valid, you also need to use  
validates\_presence\_of[http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000941](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000941)  
. "

What am I missing??

> Blessed Be
> 
> Phillip
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Matt H [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
