1
2 모델이 있습니다.Sunspot과의 연관성으로 검색하는 방법은 무엇입니까?
class UserPrice < ActiveRecord::Base
attr_accessible :price, :product_name
belongs_to :user
belongs_to :product
searchable do
integer :product_id do
product.map(&:name)
end
end
# Associations on form like "choosing a category".
def product_name
product.name if product
end
def product_name=(name)
self.product = Product.find_or_create_by_name(name) unless name.blank?
end
end
---------------------------------------------------------------------------------
class Product < ActiveRecord::Base
attr_accessible :name
has_many :user_prices
has_many :users, :through => :user_prices
end
내 UserPrice 모델을 검색하지만 제품 이름으로 검색하고 싶습니다. 블록 내부에서 어떻게 이루어 집니까?