I'm trying to replicate a join in RoR that I can do in SQL very
simply.
Three tables/models that I have are: Users, Users_Activities,
Activities and Codes.
Users and Activities have appropriate has_many associations through
Users_Activities model, so it's easy to do a join to get all
activities for a given user.
Codes, on the other hand, is a different story. It's kind of a
"repository" of all codified data. For example, the Activity table
has a "Activity Type" field that is an integer field. To get the
actual Activity Type name, you have to look it up in the Codes table
like so (joining with user table to get all activities for user id
"1"):
select activities.*, codes.name from activities, users_activities,
codes
where users_activities.user_id = 1
and users_activities.activity_id = activities.id
and activities.activity_type = codes.id
I can do part of the above query if i don't include the Codes table
like so:
Thanks, but this doesn't seem to get me the fields from the Codes in
the ResultSet - and it also tries to do
activities.id = codes.id
when it should really be
activities.activity_type = codes.id
will keep looking - thanks though!