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
class Account < ActiveRecord::Base
class Coach < ActiveRecord::Base
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 =
: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
How do I resolve this?
Thanks in advance for your help and time.