English 中文(简体)
相关记录上的搜索逻辑OR条件
原标题:Searchlogic OR conditions on associated records

Rails 2.3.5 Searchlogic 2.3.27

我有以下型号;

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

我目前正试图让Searchlogic接受“OR”条件,以便在病毒和细菌模型之间进行搜索;

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

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

作用域“_or_viral_agents_virs_name_like”未被识别,尽管这两个作用域都可以在没有“”的情况下工作。返回的输出应显示细菌名称类似“VTEC O157”或病毒名称类似“NOROVIRUS”的所有记录(“any”子句允许每个记录有多个名称)。

有什么想法吗?

最佳回答

我可能错了,但我认为这不起作用,除非使用来自同一模型的列并针对单个条件进行测试。请参阅Github问题页面进行讨论。

你最好的选择IMO是写你自己的范围。

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签