代码之家  ›  专栏  ›  技术社区  ›  james

适用于SQLite,但不适用于PostGreSQL…属性不是1

  •  -2
  • james  · 技术社区  · 9 年前

    我的代码中有一个语句:

    RentalItem.last.maintenance_orders.where("status_id IS NOT 2").present?
    

    在开发模式下工作良好,但在生产环境下不能在PostGreSQL中工作。问题是,语法是使代码工作的唯一方法,因为在我的陈述中,如果一个孩子 maintenance_order 有一个 status_id 属于 nil ,然后我想让 .present? 命令其他语法被忽略 Rails ActiveRecord find children where attribute is NOT a given value

    关于如何改变这个语法有什么想法吗?

    1 回复  |  直到 8 年前
        1
  •  0
  •   Sam Coles    9 年前

    尝试:

    RentalItem.last.maintenance_orders.where("status_id <> 2 or status_id is null").present?
    
    推荐文章