activerecord-hackery / meta_search

Object-based searching (and more) for simply creating search forms. Not currently maintained.
http://erniemiller.org/2013/11/17/anyone-interested-in-activerecord-hackery/
MIT License
903 stars 140 forks source link

Multi-level polymorphic associations cannot be traversed #17

Closed perchard closed 13 years ago

perchard commented 13 years ago

Is it simply a limitation that multi-level polymorphic associations cannot be traversed? Please find below my use case.

Given:

class Document < ActiveRecord::Base
  belongs_to :documentable, :polymorphic => true
end

class Subject < ActiveRecord::Base
  has_many :documents, :as => :documentable
  belongs_to :program
end

class Program < ActiveRecord::Base
  has_many :subjects
end

When:

Document.search(:documentable_subject_type_program_name_contains => "Query")

Then:

NoMethodError: You have a nil object when you didn't expect it!

Full error: https://gist.github.com/900229

The following works:

Document.search(:documentable_subject_type_program_id_equals => 1)

Thanks for the great gem!

ernie commented 13 years ago

It definitely isn't an intentional limitation. Could you submit a failing test?