0

我可以在模型中设置虚拟访问器并将此访问器设置为 Thinking Sphinx 中的字段或属性吗?我正在尝试这样,但收到错误“nil: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
4

1 回答 1

1

我用明确的 sql 做到了这一点:

has "GROUP_CONCAT((price * currencies.rate) SEPARATOR ',')", :as => "price_in_base_currency", :type => :integer
于 2013-04-29T13:48:54.380 回答