微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用连接的太阳黑子搜索关联

如何解决使用连接的太阳黑子搜索关联

以下是模型列表及其关系:

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,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,optional: false
end

正如你在我的课堂模型中看到的那样,部分有很多学生。由于连接的帮助,我可以搜索学生“first_name”和学生“last_name”。有没有可能的方法搜索学生的联系电话。使用连接???或者在 Section 模型中搜索联系人号码的解决方法是什么?

解决方法

在我的 ContactNumber 模型中,我创建了另一个连接

class ContactNumber
  searchable do
    string :ref_id do
      if resource_type == "Student"
        [resource.resource_type,resource.resource_id].join("_").downcase()
      end
   end
end

在我的学生模型中

searchable do 
  string :ref_id do
  [resource_type,resource_id].join("_").downcase()
end

  join(:content,prefix: "contact_number",target: ContactNumber,type: :text,join: {from: :ref_id,to: :ref_id})
end

最后在我的 Section 类

class Section 
   searchable do
    string :ref_id do
  [self.class.name,id].join("_").downcase()
end
join(:content,prefix: "number",target: ContactPerson,to: :ref_id})
   end
end

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?