简体   繁体   English

关联记录上的Searchlogic“或”条件

[英]Searchlogic 'OR' conditions on associated records

Rails 2.3.5 Searchlogic 2.3.27 Rails 2.3.5 Searchlogic 2.3.27

I have the following models; 我有以下型号;

class Outbreak < ActiveRecord::Base
  has_many :bacterial_agents, :dependent => :destroy
  has_many :bacteria, :through => :bacterial_agents

  has_many :viral_agents, :dependent => :destroy
  has_many :viruses, :through => :viral_agents
end

class BacterialAgent < ActiveRecord::Base
  belongs_to :outbreak
  belongs_to :bacterium
end

class Bacterium < ActiveRecord::Base
  has_many :bacterial_agents
  has_many :outbreaks, :through => :bacterial_agents
end

class ViralAgent < ActiveRecord::Base
  belongs_to :outbreak
  belongs_to :virus
end

class Virus < ActiveRecord::Base
  has_many :viral_agents
  has_many :outbreaks, :through => :viral_agents
end

I'm currently trying to get Searchlogic to accept an "OR" condition for a search between the models Virus and Bacterium, along these lines; 我目前正在尝试让Searchlogic接受“ OR”条件,以便沿着这些思路在Virus和Bacterium模型之间进行搜索。

params[:search] = {"bacterial_agents_bacterium_name_like_any" => "VTEC O157", "viral_agents_virus_name_like_any" => "NOROVIRUS"}

@search = Outbreak.search(params[:search])

The scope "_or_viral_agents_virus_name_like" isn't recognised although both scopes work without the " or ". 无法识别范围“ _or_viral_agents_virus_name_like”,尽管两个范围都在没有“” “”的情况下工作。 The returned output should show all records where the bacteria name is like "VTEC O157" or the virus name is like "NOROVIRUS" (the "any" clause is to allow multiple names for each). 返回的输出应显示所有记录,其中细菌名称如“ VTEC O157”或病毒名称如“ NOROVIRUS”(“ any”子句允许每个名称使用多个名称)。

Any ideas? 有任何想法吗?

I could be wrong, but I don't think this works except when using columns from the same model and testing against a single condition. 我可能是错的,但是除了使用来自相同模型的列并针对单个条件进行测试时,我认为这不起作用。 See the Github issues page for a discussion. 请参阅Github问题页面进行讨论。

Your best bet IMO is to write your own scope. IMO最好的选择是编写自己的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM