对关联分页时将对缺少的 FROM 子句条目进行分页
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查development.log中为WORKING和NON WORKING语句生成的Sql查询
Check the development.log for the Sql query generated for WORKING and NON WORKING statement