views:

320

answers:

2

Is this possible?

In an events system an event can have multiple times. (ie, if it is a 3 day event and each day it's at a different time). Each time has a place associated with it. Finally, each place has an address associated with it. Now, can I reference those addresses through my event model?

I'm thinking something conceptually like this:

class Event < ActiveRecord::Base
    has_many :TimePlaces
    has_many :Places :through => :TimePlaces
    has_many :Addresses :through => :PlaceAddresses :through => :Places
+3  A: 

This is the right syntax.

class Event < ActiveRecord::Base
    has_many :time_places
    has_many :places, :through => :time_places
    has_many :addresses, :through => :places

Despite this should work, you might want to redesign your database. Running a query with too many joins requires an intensive database elaboration and drastically slows down your application.

Simone Carletti
I like your idea better about limiting my joins. There should be a more efficient way for me to do this, and I'll find that way.
kd7iwp
A: 

also keep in mind convention is to be alphabetical within the join table syntax therefore it should be has_many :places, :through => :place_times

nacengineer