gpt4 book ai didi

ruby-on-rails - 查找具有非空字段的所有记录?

转载 作者:行者123 更新时间:2023-12-04 02:57:14 24 4
gpt4 key购买 nike

我试图定义两个变量,如下所示:

  • @orders = Customer.find_all_by_order_date(nil)
  • @nonorders = Customer.find_all_by_order_date(!nil)

  • 第一个可以正常工作,但是第二个则不能。我如何找到那些order_date字段不是nil的客户?
    @nonorders = @customer.orders.find(:all, :conditions => "@customer.orders.order_date IS NOT NULL")

    给我以下错误:
    undefined method 'extract_options_from_args!' for ActiveRecord::Base:Class
    我尝试更改条件,例如 @orders.order_date@customer.order.order_date等。是什么导致此错误?谢谢!

    最佳答案

    Rails3:

    @nonorders = Customers.where("customers.date IS NOT NULL")

    Rails2:
    @nonorders = Customers.find(:all, :conditions => "customers.date IS NOT NULL")

    关于ruby-on-rails - 查找具有非空字段的所有记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3825304/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com