我可以在模型中设置虚拟访问器,并将此访问器设置为Thinking Sphinx中的字段或属性吗?我正在尝试这样但是为nil获取错误“undefined method`type':NilClass “ 索引模型:
...
has price_in_base_currency
并在模型中:
..
attr_accessible :price
attr_accessor :price_in_base_currency
belongs_to :currency
before_save :set_accessor
def set_accessor
price_in_base_currency = price * currency.rate
end
答案 0 :(得分:1)
我用清楚的sql做了这个:
has "GROUP_CONCAT((price * currencies.rate) SEPARATOR ',')", :as => "price_in_base_currency", :type => :integer