does each hall have to be specifically designated as hallx?
and do halls exist independently of spectacle?
Assuming that halls exist independently, it sounds like having a join
table and position attributes on the join should work
spectacle
has_many :halls
spectacle_hall_join
belongs_to :hall
belongs_to :spectacle
hall
has_many :spectacles, through: spectacle_hall_join
should do the trick
if you really need to have the ability to call hallx you could add a
scope to the join
scope :position, lambda {|x| where position: x} # assumes code
calls only, if users can supply a value you will want to prevent XSS on this
you can take this further to get exactly what you need.
Hope this helps.
On 5/28/14, 9:30 AM, Simon Eric 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?
> It is possible to do this type of association?
> How can i get all of Hall's seats through spectacle that i created?
>
--
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/5385E8C5.20304%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment