Hi, I''m fairly new to Ruby and Rails. I''m trying to get my
models
validating and I''ve run into a problem.
I''ve got two models User and Contact. User belongs_to contact and
contact has_one user.
A Contact can exist without a User, however a User cannot exist without
a corresponding Contact.
Also, the Contact model contains an email address. This email address
can be null, but if there is a User corresponding with the Contact then
there must be an email address.
So basically, upon creating a user I need to check that (a) the
contact_id of the user exists in Contacts, and (b) that the email field
of the corresponding Contact is not blank.
Is there a special Rails way of doing this (particularly part a), or do
I need to create my own validation code (which I assume will be the case
for part b no matter what)?
Also, am I right in assuming that if I use contact.email within an
instance of my User class it will pick out the corresponding Contact for
said User?
Thanks for any help or pointers!
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---