Forum: Ruby on Rails Using :joins - How to help Rails populate a list of records

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Iván Vega R. (Guest)
on 2006-03-11 02:28
(Received via mailing list)

Due to some performance issues, I want to use a custom query for a find

  def find_in_state(state)
    State.find :all,
               :limit => 10,
               :conditions => [' = ? AND ' +
                               ' = c.state_id AND c.state_id = ? AND
' +
                               ' = col.county_id AND ' +
                               ' = l.state_id AND l.state_id = ? AND
' +
                               ' = l.group_id AND ' +
                               'sc.location_id =',
                               state, state, state],
               :joins => 's, counties c, colonies col, locations l,
groups g, schools sc',
               :select => 'c.*, col.*, l.*, g.*, sc.*'

Basically, it searches for schools in a specific state, and joins with
related tables, like "counties", "locations", "colonies"...

However, as I'm aware, it's not possible to tell from which table does
each column belong to, as there are column names shared between
different tables.

So I'm wondering if it's possible to give Rails a hand so it builds
the object relationship like so:

@schools = find_in_state(9) -> this should build:



If it isn't possible, how does one do it manually?

Thanks in advance!

Ivan V.
This topic is locked and can not be replied to.