【问题标题】:how to express nested where statements for postgres in rails?如何在rails中表达postgres的嵌套where语句?
【发布时间】:2019-10-02 21:49:22
【问题描述】:

我有一个Job 资源,example 作为整数变量。 examplePost 的id,属于User。现在我想查询每条Job 记录,其中example 等于Post,其中该帖子的ID 等于current_user,例如:

@jobs = Job.where(example: Post.where(user_id: current_user.id)).all

这种语法对于测试环境中的 sqlite 似乎是“正确的”,但在 heroku 生产服务器上的 postgres 中会中断。

在尝试上述语法时,Postgres 出现以下错误:

HINT: No operator matches the given name and argument types. You might need to add explicit type casts.

如何以 Rails 方式表达?

【问题讨论】:

  • 可以分享Job模型吗?

标签: ruby-on-rails postgresql where-clause


【解决方案1】:

发现错误..example 是字符串而不是整数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多