rails: Bug with namespaced ActiveRecord models on 4.1.x (PostgreSQL)

I’ve come up against a bug with ActiveRecord when using namespaces models and polymorphic associations, it’s a common use-case so should probably be fixed before a 4.2 release.

Error:

NoMethodError: undefined method `relation_delegate_class' for Comment:Module

Example:

class Post::Base < ActiveRecord::Base
  self.table_name = 'posts'
end

class Post::Special < Post::Base
  has_many :comments, as: :commentable
end

class Comment::Base < ActiveRecord::Base
  self.table_name = 'comments'
  belongs_to :commentable, polymorphic: true
end

class Comment::Special < Comment::Base
end

Post::Special.first.comments

# => NoMethodError: undefined method `relation_delegate_class' for Comment:Module

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 29 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I’m using class_name: '::Comment' as a workaround for now.

It looks like this is the only issue on the Rails repository with the good first issue label.

If anyone comes here and wants to take a crack at it, @eileencodes has indicated that the best candidate to fix this and get merged is this PR by @tiagonbotelho: https://github.com/rails/rails/pull/30778

This PR was closed a few months ago due to being stale (unfortunately ☹️ ). It does appear that the Rails-Core team would like a test with the implementation.

Anyone looking to pick this up ( @ngetahun ? ) that might be your best bet.

If you’re new to Rails and unsure how to approach the testing side of things, Eileen’s talk here should be more than enough to get you rolling.

Is this still an issue with master? We wouldn’t accept a backport for Rails 4.1 at this time.