【发布时间】:2019-04-14 17:43:57
【问题描述】:
我有一个模型Property,并且我有一个定义如下的虚拟属性:
def uid_type
if mls? && mls.to_i != 0
"MLS"
elsif property_identifier? && property_identifier.to_i != 0
"PID"
else
"ID"
end
end
如果我有一个属性p,当我查询那个虚拟属性时,我看到的是这样的:
> p.uid_type
=> "MLS"
基本上,我想做的是在我的模型上创建一个范围以返回所有具有uid_type == 'MLS' 的属性。
我该怎么做?
编辑 1
如果我试试这个:
Property.where('properties.uid_type == "MLS"').count
(4.6ms) SELECT COUNT(*) FROM "properties" WHERE (properties.uid_type == "MLS")
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column properties.uid_type does not exist
LINE 1: SELECT COUNT(*) FROM "properties" WHERE (properties.uid_typ...
【问题讨论】:
标签: ruby-on-rails activerecord ruby-on-rails-3.2