Forum: Ruby on Rails Make a STI-compatible finder for a polymorphic column ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Nicolas B. (Guest)
on 2008-11-03 15:45

I've got a model with a polymorphic column and STI models.
I've added a finder to search for specific types.
How can I search for a specific model that is STI because Rails stores
the mother class name ?

class Activity < ActiveRecord::Base
  belongs_to :item, :polymorphic => true

  named_scope :filter_items, lambda { |i| { :conditions => { :item_type
=> i } } }

class Person < ActiveRecord::Base

class Site < ActiveRecord::Base

class Event < Site

class Place < Site

Activity.filter_items('Person') works but Activity.filter_items('Event')
and Activity.filter_items('Place') don't work because Rails stores
'Site' in item_type column...

I would like to be able to search through STI and non-STI models...

Thanks for your answers,
This topic is locked and can not be replied to.