On 28 May 2014 14:30, Simon Eric <lists@ruby-forum.com> wrote:
> i want to associate one model with 4 models. For example i call a first
> model Spectacle and call others Hall1, Hall2, Hall3 and Hall4. All of
> Halls have the same attributes: id and seat. Each Hall have 10 seats.
> I want to create an spectacle on the database and associate it with any
> Hall.
> Problems:
> How can i do this association in rails?
Just have one halls table, with an additional field of, for example,
hall_number. Then have spectacle belongs_to hall, hall has_many
spectacles (assuming this is what you want).
> It is possible to do this type of association?
> How can i get all of Hall's seats through spectacle that i created?
To get all the seats for a spectacle, assuming that hall has_many seats use
@spectacle.hall.seats
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvu7h5e7OVZYGRsUfsJ7sd8dkN6XG1xDLCH7nmM6NE0oA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment