Activerecord Nested:包含失败

时间:2010-01-14 02:19:22

标签: ruby-on-rails activerecord nested-includes

我有一个使用'will_paginate'的AR查询,如下所示:

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]

我在订单条款中收到错误:

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

我想按一个人的姓氏订购。如您所见,我已将用户和个人包含在嵌套包含中。用户属于具有此声明的人:

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

Person是Party的子类:

class Person < Party

Party有一个last_name字段

1 个答案:

答案 0 :(得分:3)

order by应为table_name.column,类似于people.last_name