Question

I have an AR query using 'will_paginate' that looks like this:

paginate  :all, 
                :page => criteria[:page], 
                :per_page => criteria[:per_page], 
                :include => { :user, :person },
                :conditions => [conditions , criteria[:from_date], criteria[:to_date], criteria[:patient_id],criteria[:user_id]].concat(criteria[:actions]).concat(criteria[:types]).concat(criteria[:users]).concat(criteria[:statuses]).concat(criteria[:priorities]).compact,
                :order => criteria[:order]

I get an error in the order clause:

Unknown column 'user.person.last_name' in 'order clause'

I am trying to order by a person's last name. As you can see I have included user and person in a nested include. User belongs to person with this statement:

belongs_to :person, :class_name => 'Party', :foreign_key => 'person_id', :with_disabled => true

Person is a subclass of Party:

class Person < Party

Party has a last_name field

Was it helpful?

Solution

The order by should be table_name.column, something like people.last_name

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top