Nicolas Blanco
2008-Nov-03 13:45 UTC
Make a STI-compatible finder for a polymorphic column ?
Hi, 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 } } } end class Person < ActiveRecord::Base end class Site < ActiveRecord::Base end class Event < Site end class Place < Site end 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, Nicolas. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---