Activerecord 嵌套:包含失败

发布于 2024-08-18 04:21:08 字数 964 浏览 1 评论 0原文

我有一个使用“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]

我在 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字段

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青巷忧颜 2024-08-25 04:21:08

排序依据应该是 table_name.column,类似于 people.last_name

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文