Rails, search item in different model?

Posted by Danny McClelland on Stack Overflow See other posts from Stack Overflow or by Danny McClelland
Published on 2010-05-17T14:02:25Z Indexed on 2010/05/17 14:10 UTC
Read the original article Hit count: 258

Filed under:
|
|

Hi Everyone,

I have a kase model which I am using a simple search form in. The problem I am having is some kases are linked to companies through a company model, and people through a people model.

At the moment my search (in Kase model) looks like this:

# SEARCH FACILITY
  def self.search(search)
    search_condition = "%" + search + "%"
    find(:all, :conditions => ['jobno LIKE ? OR casesubject LIKE ? OR transport LIKE ? OR goods LIKE ? OR comments LIKE ? OR invoicenumber LIKE ? OR netamount LIKE ? OR clientref LIKE ? OR kase_status LIKE ? OR lyingatlocationaddresscity LIKE ?', search_condition, search_condition, search_condition, search_condition, search_condition, search_condition, search_condition, search_condition, search_condition, search_condition])
  end

What I am trying to work out, is what condition can I add to allow a search by Company or Person to show the cases they are linked to.

@kase.company.companyname

and

company.companyname

don't work :(

Is this possible?

Thanks,

Danny

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about search