Sunday, July 22, 2012

Re: [Rails] Multiple associations to the same model

On Sun, Jul 22, 2012 at 5:13 PM, Matt Harrison <lists@ruby-forum.com> wrote:

> Lets say the other model defines a room. A room should be able to have
> one table and one chair. Unfortunately, as they both refer to the same
> model, I'm a loss on how to do it.

You could have attributes called table and chair, each referring to a
furniture. Upon saving, have a validation check that table is a table
and chair is a chair. I'd recommend doing this with a furniture_type
method, rather than directly checking the range; if you somehow manage
to be able to change this ID silliness, you can then have the method
check something else instead (such as a enumerated type attribute).

-Dave

--
Dave Aronson, Cleared/Remote Ruby on Rails Freelancer
(NoVa/DC/Remote); see www.DaveAronson.com, and blogs at
www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate