I have a structure set up
class Organization < ActiveRecord::Base
has_many :groups
end
class Group < ActiveRecord::Base
has_many :conversations, inverse_of: :group
belongs_to :organization
end
class Conversation < ActiveRecord::Base
belongs_to :group, inverse_of: :conversations
has_many :messages, as: :subject
end
class Message < ActiveRecord::Base
belongs_to :subject, polymorphic: true
end
When I run the following search, there are no issues. It works great.
Message.search({subject_conversation_type_group_id_eq: 1})
# => [<#Message>, <#Message>]
But here's the problem: If I add the next belongs_to association, it fails:
Message.search({subject_conversation_type_group_organization_id_eq: 1})
# => ActiveRecord::ConfigurationError: Association named 'group' was not found for 'Message'; perhaps you misspelled it?
Also, when running the search from the level above the polymorphism, it also works fine.
Conversation.search({group_organization_id_eq: 1})
# => [<#Conversation>]
Running Rails 3.0.20 and Ruby 1.9.2-p320