对关联分页时将对缺少的 FROM 子句条目进行分页

发布于 2024-12-11 07:45:53 字数 864 浏览 0 评论 0原文

我使用 Rails 2.3.5、will_paginate-2.3.15 和 postgress。 我有 2 个属于同一张表。 如果我首先搜索属性,然后搜索别名表属性,则会抛出异常。如果我在它起作用的条件下颠倒顺序...

class House
  belongs_to :owner, :class => "User"
  belogns_to :creator, :class => "User"
end

House.paginate(
  :page=>1, 
  :include=>[:creator, :owner], 
  :per_page=>20, 
  :conditions=>"houses.city ILIKE E'%new yo%' and owners_houses.architect ILIKE E'%tom%'")

在日志中引发

ActiveRecord::StatementInvalid: PGError: ERROR:  missing FROM-clause entry for table "owners_houses", 

no joins in from 子句

这有效:

House.paginate(
  :page=>1, 
  :include=>[:creator, :owner], 
  :per_page=>20, 
  :conditions=>"owners_houses.architect ILIKE E'%tom%' and houses.city ILIKE E'%new yo%'")

这是 will_paginate 中的错误吗?为什么会发生这种情况?

I work with rails 2.3.5, will_paginate-2.3.15 and postgress.
I have 2 belongs_to's to the same table.
If i first search on a attribute and then on the aliased table attribute then it throws an exception. If I reverse the order in the conditions it works...

class House
  belongs_to :owner, :class => "User"
  belogns_to :creator, :class => "User"
end

House.paginate(
  :page=>1, 
  :include=>[:creator, :owner], 
  :per_page=>20, 
  :conditions=>"houses.city ILIKE E'%new yo%' and owners_houses.architect ILIKE E'%tom%'")

raises

ActiveRecord::StatementInvalid: PGError: ERROR:  missing FROM-clause entry for table "owners_houses", 

in logs no joins in from clause

This works:

House.paginate(
  :page=>1, 
  :include=>[:creator, :owner], 
  :per_page=>20, 
  :conditions=>"owners_houses.architect ILIKE E'%tom%' and houses.city ILIKE E'%new yo%'")

Is this a bug in will_paginate? Why is this happening?

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

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

发布评论

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

评论(1

瞎闹 2024-12-18 07:45:53

检查development.log中为WORKING和NON WORKING语句生成的Sql查询

Check the development.log for the Sql query generated for WORKING and NON WORKING statement

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