Heroku 上的 ActiveRecord 错误
我有以下代码在开发环境 (SQLite) 上运行,但在 Heroku (PostgreSQL) 上生成错误:
@shoes_with_images = Shoe.
select( "shoes.id, shoes.collection_id, count( shoe_images.shoe_id ) as c" ).
joins( :shoe_images ).
group( "shoes.id" ).
having( "c > 0" ).
where( :collection_id => params[:id] ).
offset( (page - 1) * SHOES_PER_PAGE ).
limit( SHOES_PER_PAGE ).all
错误消息:
ActiveRecord::StatementInvalid (PGError: ERROR: column "c" does not exist
如何更正此查询以使其在 Postgres 上运行?
I have following code working on a development environment (SQLite) but generating an error on Heroku (PostgreSQL):
@shoes_with_images = Shoe.
select( "shoes.id, shoes.collection_id, count( shoe_images.shoe_id ) as c" ).
joins( :shoe_images ).
group( "shoes.id" ).
having( "c > 0" ).
where( :collection_id => params[:id] ).
offset( (page - 1) * SHOES_PER_PAGE ).
limit( SHOES_PER_PAGE ).all
Error message:
ActiveRecord::StatementInvalid (PGError: ERROR: column "c" does not exist
How can I correct this query to make it work on Postgres?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试更改
我
不是 100% 确定,但我认为查询处理器在处理 group by 或 having 语句时没有别名“c” 。
Try changing
with
I'm not 100% sure, but I think that the query processor doesn't have the alias "c" when it processes the group by or having statements.