Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Polymorphic advanced association raises unexpected error #125

Open
stevenspiel opened this issue Oct 31, 2014 · 2 comments
Open

Polymorphic advanced association raises unexpected error #125

stevenspiel opened this issue Oct 31, 2014 · 2 comments

Comments

@stevenspiel
Copy link

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

@nishanthan144
Copy link

@stevenspiel Hi, did you got any solution for this problem?.

@stevenspiel
Copy link
Author

no... I just had to use Arel to create the query manually.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants