has_one through belongs_to

11 views
Skip to first unread message

Michel Pigassou

unread,
Jul 7, 2011, 10:41:07 AM7/7/11
to rubyonra...@googlegroups.com
Hi.

My model data is the following:
- Place
- User
- Checkin

Instead of having a Checkin that belongs to both User and Place, I chose to add another model, Program, that allows to list all the places a user can checkin into, and also hide the checkins he's no longer involved in (= the user sign out of a specific program).
That give me crazy relationships:
Program has_many Checkin (and a double belongs_to Place and User)
Checkin belongs_to Program
User has_many Program
Place has_many Program
Place has_many Checkin through Program

In order to access a place or a user from a checkin, I do a has_one through (program): Checkin has_one User through Program. It allows me to have clean ActiveRecord relationships.
But I don't know if it is the most suitable, and if has_one is made for this (apparently not really).

Reply all
Reply to author
Forward
0 new messages