Find :order =>

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

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

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

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

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

maybe orginisationes? (es)

maybe orginisationes? (es)

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

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

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