0

Trying to implement a search logic search that uses associations with STI but I’m having a problem where it is not select the STI records as the subclass but the parent.

Example:

class Users
end

class Artist < User has many :agents, :through => :agents artists end

class Agent < User has many :artists, :through => :agents artists end when i do a search for "artist agents company like", it is searching based on the agents as users rather than as agents:

select * from users WHERE users.company LIKE

rather than

select * from users AS agents WHERE agents.company LIKE

Wondering if I can pre-empt this problem at the ActiveRecord class level (eg in the association I was thinking that if you could specify that the agents would get loaded :as=>:agent or something along those lines), or if I would need to patch searchlogic or what else I could do to accomplish this.

One other option that occurred to me, and I dread the idea, is to add a field on the user table that includes a listing of the person’s agencies. eg users.agencies => Agency One Name,Agency Two Name

Pesto
  • 23,810
  • 2
  • 71
  • 76
Gordon Isnor
  • 2,065
  • 1
  • 19
  • 32

1 Answers1

0

I found a solution that seems to be working well, I added a named scope on the artist class:

named scope :agencies include, lambda { |c| { :joins=> :agents,:conditions => { :agents users => { :company => c } } } }

The search field is now called search[artist agencies include]

Gordon Isnor
  • 2,065
  • 1
  • 19
  • 32