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)}
然后用
模型搜索。完成您不需要自我。
。