views:

224

answers:

1

This is probably quite simple but I haven't yet been able to wrap my head around the problem.

I have 3 tables... (well more than that) but in this scenario 3 that matter.

Places Bookings and Ratings

Places has_many bookings

Each booking has_one rating (because the user only rates once) and belongs_to (a) Place

Ratings belong_to (a) Booking

So even though bookings has only one rating, places has_many ratings through bookings as places has many bookings also

but this doesn't seem to work? All the rest seem to.

Bookings has place_id and Ratings has a booking_id, and I've been successful with all other has_many through associations... just not the has_one? Any ideas? Thanks

addition: if i change Bookings to has_many :ratings it works... but bookings will only ever have one rating per booking... so this doesn't seem like a good thing.

Invalid source reflection macro :has_one for has_many :ratings, :through => :bookings.  Use :source to specify the source reflection.
+1  A: 

has_many :through doesn't work with has_one relations on the join model; see the following Rails tickets for details:

If possible, the best solution is probably to modify your relations so that a Booking belongs_to a Rating rather than has_one Rating.

Pär Wieslander
Great, thanks! I just bumped rails up to 2.3.4 from 2.3.2 and now the association seems to work.
holden