【发布时间】:2016-05-02 14:45:33
【问题描述】:
我有 3 节课。
Product, Command, CommandOption
我的搜索非常好用。按产品搜索。
但是我想通过 CommandOption 搜索并返回我的 Product 对象,这是怎么做到的?
class Product < ActiveRecord::Base
extend FriendlyId
friendly_id :slug, use: :slugged
searchkick
has_many :commands
def search_data
{
name: name,
#commands (has_many)
command_captions: commands.map(&:caption).join(' '),
command_numbers: commands.map(&:number).join(' '),
#if I write here, then get error
#command_option_caption: command_options.map(&:caption).join('')
}
end
end
class Command < ActiveRecord::Base
belongs_to :product
has_many :command_options
end
class CommandOption < ActiveRecord::Base
belongs_to :command
end
对不起我的英语
【问题讨论】:
标签: ruby-on-rails ruby elasticsearch searchkick