Keyword search

I’m having trouble trying to implement a basic keyword search in my
app. I’m trying to search through multiple tables. I m using a vendor
plugin for the conditions(which should not effect the search).
The association in the models is as following

The furni model contains this association to the raider model:

belongs_to :raider, :foreign_key => “original_raider_id”

The controller call

unless params[:search].blank?
@furni_pages, @furnii = paginate :furnii,
:conditions => Furni.conditions_by_like(params[:search]),
:per_page => 10,
:order => order_from_params

So what I’m trying to do is to have the search go through the raiders
table as well. I do not know if it’s possible. I tried joins with no
luck. Hope some one can give me a pointer. Thanks

the include statement should work:

@furni_pages, @furnii = paginate :furnii,
:include => “raiders”,
:conditions => Furni.conditions_by_like(params[:search]),
:per_page => 10,
:order => order_from_params

then you could enhance your conditions with something like:
“raiders.column_name=‘whatever’”

important point is, that if you use include, you’ll have to
specify the table name for all fields that exist in both tables
(eg created_at)

Thorsten M. wrote:

the include statement should work:

@furni_pages, @furnii = paginate :furnii,
:include => “raiders”,
:conditions => Furni.conditions_by_like(params[:search]),
:per_page => 10,
:order => order_from_params

then you could enhance your conditions with something like:
“raiders.column_name=‘whatever’”

important point is, that if you use include, you’ll have to
specify the table name for all fields that exist in both tables
(eg created_at)

how do I incorporate the “raiders.column_name=‘whatever’” in the
existing conditions?

how do I incorporate the “raiders.column_name=‘whatever’” in the
existing conditions?

This may depend on what exactly this
Furni.conditions_by_like(params[:search]) returns.

in general:

:conditions => { “raiders.column_name” => “something”,
Furni.conditions_by_like(params[:search]) })

may work, if your method returns a simple conditions string.
If it returns the conditions in Array or Hash form, you may have to
merge it with the additional conditions for raiders.

Thorsten M. wrote:

how do I incorporate the “raiders.column_name=‘whatever’” in the
existing conditions?

This may depend on what exactly this
Furni.conditions_by_like(params[:search]) returns.

in general:

:conditions => { “raiders.column_name” => “something”,
Furni.conditions_by_like(params[:search]) })

may work, if your method returns a simple conditions string.
If it returns the conditions in Array or Hash form, you may have to
merge it with the additional conditions for raiders.

Thanx for your help, but it does not work. The conditions_by_like
function is a vendor plug in and it performs a generic search(below). I
do not know what I’m doing wrong.

def conditions_by_like(value, *columns)
columns = self.user_columns if columns.size==0
columns = columns[0] if columns[0].kind_of?(Array)
conditions = columns.map {|c|
c = c.name if c.kind_of?
ActiveRecord::ConnectionAdapters::Column
"#{c} LIKE " +
ActiveRecord::Base.connection.quote("%#{value}%")
}.join(" OR ")
end

CONTROLLER CALL

def search
unless params[:search].blank?
@furni_pages, @furnii = paginate :furnii,
:include => “raider”,
#:conditions => {“raiders.column_name” => “email”,
Furni.conditions_by_like(params[:search])},
:conditions => {“raiders.column_name=‘email’”,
Furni.conditions_by_like(params[:search])},
:per_page => 10,
:order => order_from_params
else
index
end
render :partial=>‘furnilist’, :layout=>false
end