nas wrote:
> There is nothing in rails that can validate an associated record
> exists for a belongs_to relationship.
> 
> But you can use Josh Susser's fantastic validates_existence_of plugin
> that does check whether the associated record exists or not
> 
> Check out his post here here 
> http://blog.hasmanythrough.com/2007/7/14/validate-your-existence
> 
> On Jul 5, 8:44�am, Learn by Doing <[email protected]>

I've found that:

validates_presence_of   :user_id
validates_presence_of   :user

works just fine.

>From what I have been able to tell, validates_associated is meant for 
when you are constructing two or more associated models at the same 
time, and you don't want to save them unless both validate.  So your 
user validates would contain:

validates_associated    :address

which would run all the validations for the address model.  However, you 
can't at the same time have a

validates_associated    :user

line in the address model, because that will cause an infinite recursion 
loop of validations.


-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to