Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 通过伪属性搜索ActiveRecord_Ruby On Rails_Ruby_Activerecord_Ruby On Rails 5.1 - Fatal编程技术网

Ruby on rails 通过伪属性搜索ActiveRecord

Ruby on rails 通过伪属性搜索ActiveRecord,ruby-on-rails,ruby,activerecord,ruby-on-rails-5.1,Ruby On Rails,Ruby,Activerecord,Ruby On Rails 5.1,在我的模型上,我有这个方法 def complete? self.address_id && self.user_id && self.location end 是否可以使用activerecord搜索符合此条件的记录,或者我只需在每次查找中检查所有这些列是否为零?执行此操作的方法似乎是为模型创建一个范围: scope :complete, -> { where.not(address_id: nil, user_id: nil, location

在我的模型上,我有这个方法

def complete?
    self.address_id && self.user_id && self.location
end

是否可以使用activerecord搜索符合此条件的记录,或者我只需在每次查找中检查所有这些列是否为零?

执行此操作的方法似乎是为模型创建一个范围:

scope :complete, -> { where.not(address_id: nil, user_id: nil, location_id: nil)}

然后用
模型搜索。完成

您不需要
自我。