I have an accounts table and a coaches table.  The tables are as follows
(with unimportant fields deleted):

Accounts (id, name,...)
Coaches  (id, account_id, business_id, account_limit)

Each account can either have one (or none) coach at any point in time.

I have modeled these relationships in corresponding ActiveRecord classes
as follows:

class Account < ActiveRecord::Base
  has_one :coach
end

class Coach < ActiveRecord::Base
  belongs_to :account
end


I am trying to use will_paginate for paging through the list of coaches
and look-up their names from the accounts table (and some more fields).
To get to that, I am first trying to create a corresponding find query
in ActiveRecord.  Here is my query:

Coach.find :all, :select => 'c.id, a.id, a.name',
           :joins => 'as c inner join accounts as a on a.id =
c.account_id',
           :order => 'a.name'

It is only returning the following in irb:

 [#<Coach id: 99>]

That is, it fails to return the account.id (or a.id) and account.name
(or a.name)

How do I resolve this?

Thanks in advance for your help and time.

Bharat
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to