【发布时间】:2021-06-16 10:52:25
【问题描述】:
下面是模型及其关系的列表:
class Section
has_many :students, as: :resource
searchable do
integer :id
join(:first_name, prefix: "student", target: Student, type: :text, join: {from: :resource_id, to: :id})
join(:last_name, prefix: "student", target: Student, type: :text, join: {from: :resource_id, to: :id})
end
end
class Student
belongs_to :resource, polymorphic: true, optional: false
has_many :contact_number, as: :resource
searchable do
text :first_name
text :last_name
integer :id
integer :resource_id
string :first_name
string :last_name
end
end
class ContactNumber
belongs_to :resource, polymorphic: true, optional: false
end
正如您在我的班级模型中看到的那样,部分有很多学生。由于加入的帮助,我可以搜索学生“first_name”和学生“last_name”。有没有可能搜索学生联系电话的方法。使用连接???或者在 Section 模型中搜索联系人号码的解决方法是什么?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-5 sunspot sunspot-rails