On Jan 29, 11:49 am, Cory Wilkerson
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Good evening,
>
> Trying to find a good way to validate that a relationship exists. For
> instance, let''s say I have a Movie and every move HAS TO HAVE a
director
> (so, movie belongs_to director); I''ve enforced the constraint in
my
> schema but I''d like to take the abstraction up to the application.
>
> I''ve seen the validates_associated bits but I''m not sure
if that''s
> adequate. Perhaps validates_presence_of?
>
> Any help would be most welcome!
>
> --
> Posted viahttp://www.ruby-forum.com/.
Validates_associated will check the referenced object exists (ie a
director with that id is in the Directors table).
Validated_presence_of will make sure a value has been specified when
you are creating a movie (you can''t pass a null/nil value when
creating a new movie).
Between the two you should have what you need, but to be sure you
could implement a before_create filter in the Movie model if you need
to do fancy stuff.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---