scott
June 8, 2006, 5:12pm
1
Hi,
I have the following find statment
@client_pages , @clients = paginate :clients, :per_page => 20, :order =>
“organisation_id, surname”
currently im ordering by organisation_id however I need to order by the
field in the organisation table organisations.name
how can this be done?
Thanks
Scott
scott
June 8, 2006, 5:43pm
2
yes, the class starts with
class Organisation < ActiveRecord::Base
has_many :clients
When I insert the statment above changing the z to a s (uk,english
spelling), I get the error
Association named ‘organisations’ was not found; perhaps you misspelled
it?
any suggestions to what ive missed? the table name is “organisations”
Scott
scott
June 8, 2006, 5:50pm
3
On Thu, 2006-06-08 at 17:43 +0200, scott wrote:
any suggestions to what ive missed? the table name is “organisations”
does Class Clients
belongs_to :organisation
?
Craig
scott
June 8, 2006, 5:31pm
4
On Thu, 2006-06-08 at 17:12 +0200, scott wrote:
how can this be done?
assuming that this is related by something like Class Organisations has
many :clients
@client_pages , @clients = paginate(:clients,
:include => [‘organizations’],
:order_by => ‘organizations.name’,
:per_page => 20)
Craig
scott
June 8, 2006, 5:54pm
5
Craig W. wrote:
On Thu, 2006-06-08 at 17:43 +0200, scott wrote:
any suggestions to what ive missed? the table name is “organisations”
does Class Clients
belongs_to :organisation
?
Craig
yes
class Client < ActiveRecord::Base
belongs_to :organisation
scott
June 8, 2006, 6:05pm
6
maybe orginisationes? (es)
scott
June 8, 2006, 6:06pm
7
maybe orginisationes? (es)
scott
June 8, 2006, 6:02pm
8
On Thu, 2006-06-08 at 17:54 +0200, scott wrote:
yes
class Client < ActiveRecord::Base
belongs_to :organisation
I’m wondering if it’s a pluralization thing…
@client_pages , @clients = paginate(:clients,
:include => [‘organisation’],
:order_by => ‘organisation.name’,
:per_page => 20)
Craig
scott
June 8, 2006, 6:06pm
9
nope that didnt work
ive taken a quick look at the api and have tried using join instead of
include, which seems to work.
Not as ncie looking as the idea above as it needs a conditions, but
seems to be working ok for now
@client_pages , @clients = paginate :clients,
:join => ‘,organisations’,
:per_page => 20,
:conditions =>
‘clients.organisation_id = organisations.id’ ,
:order_by =>
“organisations.name, surname”
Thanks
scott
June 9, 2006, 12:05am
10
On Thu, 2006-06-08 at 18:06 +0200, scott wrote:
:join => ',organisations',
:per_page => 20,
:conditions =>
‘clients.organisation_id = organisations.id’ ,
:order_by =>
“organisations.name, surname”
the fact that you had to use a join rather than the association means
that there is something wrong with your association as you have created
it.
Craig