# Multiple model validation

**URL:** <https://www.ruby-forum.com/t/multiple-model-validation/125564>\
**Category:** Rails\
**Created:** [January 10, 2008, 6:13am UTC](https://www.ruby-forum.com/t/multiple-model-validation/125564 "2008-01-10T06:13:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![manjularaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@manjularaj](https://www.ruby-forum.com/u/manjularaj)\
**Post date:** [January 10, 2008, 6:13am UTC](https://www.ruby-forum.com/t/multiple-model-validation/125564/1 "2008-01-10T06:13:34Z")

</div>

Hi All,

For multiple model validation i have done these steps.  
inquiry model:  
class Inquiry \< ActiveRecord::Base

has\_one :request  
belongs\_to :contact  
belongs\_to :company  
belongs\_to :inquirer, :polymorphic=\>true

validates\_associated :contact, :company  
validates\_presence\_of :affiliation  
end

contact model:

class Contact \< ActiveRecord::Base

has\_and\_belongs\_to\_many :companies  
has\_one :inquiry, :as =\> :inquirer

validates\_presence\_of :first\_name, :last\_name, :phone\_number  
validates\_numericality\_of :country\_code, :only\_integer =\>true  
validates\_length\_of :country\_code, :maximum=\>5, :message =\> â€œshould not  
be more than 5 digits â€  
validates\_format\_of :email,:with =\>  
/([@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i  
end

This is working well with when iâ€™m calling the url  
http:/localhost:3000/inquiries/new?type=desiner  
Here iâ€™ll get the validation of inquiry and contact.

When iâ€™m calling the url http:/localhost:3000/inquiries/new?type=scout  
It will take only inquiry validation. It will not take contact  
validation.

Here is one problem for both types, if in inquiry model if i donâ€™t have  
any filed for validation then contact validation error messages will not  
display. In inquiry there is no such field that i can call for  
validation. So what can i do here.  
Please suggest me here
