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
cla开发者_开发知识库ss 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;
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". 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).
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.
Your best bet IMO is to write your own scope.
精彩评论