{"action":"created","issue":{"url":"https://api.github.com/repos/airblade/paper_trail/issues/474","labels_url":"https://api.github.com/repos/airblade/paper_trail/issues/474/labels{/name}","comments_url":"https://api.github.com/repos/airblade/paper_trail/issues/474/comments","events_url":"https://api.github.com/repos/airblade/paper_trail/issues/474/events","html_url":"https://github.com/airblade/paper_trail/issues/474","id":56175428,"number":474,"title":"Issue tracking history on polymorphic associations (4.0.0.beta2)","user":{"login":"mhuggins","id":169093,"avatar_url":"https://avatars.githubusercontent.com/u/169093?v=3","gravatar_id":"","url":"https://api.github.com/users/mhuggins","html_url":"https://github.com/mhuggins","followers_url":"https://api.github.com/users/mhuggins/followers","following_url":"https://api.github.com/users/mhuggins/following{/other_user}","gists_url":"https://api.github.com/users/mhuggins/gists{/gist_id}","starred_url":"https://api.github.com/users/mhuggins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhuggins/subscriptions","organizations_url":"https://api.github.com/users/mhuggins/orgs","repos_url":"https://api.github.com/users/mhuggins/repos","events_url":"https://api.github.com/users/mhuggins/events{/privacy}","received_events_url":"https://api.github.com/users/mhuggins/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/airblade/paper_trail/labels/Associations","name":"Associations","color":"e102d8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-01T19:52:21Z","updated_at":"2015-02-04T15:18:36Z","closed_at":null,"body":"Hi there!  I'm trying to use the paper_trail gem with custom version tables/abstract `PaperTrail::Version` model as well as tracking version associations.  My relevant classes and modules look like this:\r\n\r\n```ruby\r\n# config/initializers/paper_trail.rb\r\nPaperTrail::Rails::Engine.eager_load!\r\n\r\nPaperTrail::Version.module_eval do\r\n  self.abstract_class = true\r\nend\r\n\r\n# app/models/concerns/taggable.rb\r\nmodule Taggable\r\n  extend ActiveSupport::Concern\r\n\r\n  included do\r\n    has_many :taggings, as: :taggable, inverse_of: :taggable, dependent: :destroy\r\n    has_many :tags, through: :taggings\r\n  end\r\nend\r\n\r\n# app/models/question.rb\r\nclass Question < ActiveRecord::Base\r\n  include Taggable\r\n\r\n  has_paper_trail class_name: 'QuestionVersion'\r\nend\r\n\r\n# app/models/tagging.rb\r\nclass Tagging < ActiveRecord::Base\r\n  belongs_to :taggable, polymorphic: true, inverse_of: :taggings\r\n  belongs_to :tag, inverse_of: :taggings, counter_cache: true\r\n\r\n  has_paper_trail class_name: 'TaggingVersion'\r\nend\r\n\r\n# app/models/tag.rb\r\nclass Tag < ActiveRecord::Base\r\n  has_many :taggings, inverse_of: :tag, dependent: :destroy\r\n  has_many :taggables, through: :taggings\r\n\r\n  has_paper_trail class_name: 'TagVersion'\r\nend\r\n\r\n# app/models/question_version.rb\r\nclass QuestionVersion < PaperTrail::Version\r\n  self.table_name = :question_versions\r\nend\r\n\r\n# app/models/tagging_version.rb\r\nclass TaggingVersion < PaperTrail::Version\r\n  self.table_name = :tagging_versions\r\nend\r\n\r\n# app/models/tag_version.rb\r\nclass TagVersion < PaperTrail::Version\r\n  self.table_name = :tag_versions\r\nend\r\n```\r\n\r\nFor reference, my migrations are defined as:\r\n\r\n```ruby\r\nclass CreateQuestionVersions < ActiveRecord::Migration\r\n  def change\r\n    create_table :question_versions do |t|\r\n      t.string   :item_type,     null: false\r\n      t.integer  :item_id,       null: false\r\n      t.string   :event,         null: false\r\n      t.integer  :transaction_id\r\n      t.string   :whodunnit\r\n      t.text     :object\r\n      t.text     :object_changes\r\n      t.datetime :created_at,    null: false\r\n    end\r\n\r\n    add_index :question_versions, [:item_type, :item_id]\r\n    add_index :question_versions, [:transaction_id]\r\n  end\r\nend\r\n\r\nclass CreateTagVersions < ActiveRecord::Migration\r\n  def change\r\n    create_table :tag_versions do |t|\r\n      t.string   :item_type,     null: false\r\n      t.integer  :item_id,       null: false\r\n      t.string   :event,         null: false\r\n      t.integer  :transaction_id\r\n      t.string   :whodunnit\r\n      t.text     :object\r\n      t.text     :object_changes\r\n      t.datetime :created_at,    null: false\r\n    end\r\n\r\n    add_index :tag_versions, [:item_type, :item_id]\r\n    add_index :tag_versions, [:transaction_id]\r\n  end\r\nend\r\n\r\nclass CreateTaggingVersions < ActiveRecord::Migration\r\n  def change\r\n    create_table :tagging_versions do |t|\r\n      t.string   :item_type,     null: false\r\n      t.integer  :item_id,       null: false\r\n      t.string   :event,         null: false\r\n      t.integer  :transaction_id\r\n      t.string   :whodunnit\r\n      t.text     :object\r\n      t.datetime :created_at,    null: false\r\n    end\r\n\r\n    add_index :tagging_versions, [:item_type, :item_id]\r\n    add_index :tagging_versions, [:transaction_id]\r\n  end\r\nend\r\n\r\nclass CreateVersionAssociations < ActiveRecord::Migration\r\n  def change\r\n    create_table :version_associations do |t|\r\n      t.integer  :version_id\r\n      t.string   :foreign_key_name, null: false\r\n      t.integer  :foreign_key_id\r\n    end\r\n\r\n    add_index :version_associations, [:version_id]\r\n    add_index :version_associations, [:foreign_key_name, :foreign_key_id], name: 'index_version_associations_on_foreign_key'\r\n  end\r\nend\r\n```\r\n\r\nThe error pops up in the [`save_associations` method of `has_paper_trail.rb`](https://github.com/airblade/paper_trail/blob/v4.0.0.beta2/lib/paper_trail/has_paper_trail.rb#L376).  The call to `assoc.klass` is returning `Taggable`, which from my model definitions is supposed to be a polymorphic association.  Instead, it's resolving to my `Taggable` module, and attempting to call `paper_trail_enabled_for_model?` on it, which is not defined.\r\n\r\nIt seems that instead of trying to classify the polymorphic association via `assoc.klass` (which returns `Taggable`), it would make more sense to call `send(assoc.name).class` (which in this case would return `Question`).  Unfortunately, I'm not sure if this will fix everything since the following call would end up storing the `foreign_key_name` as `taggable_id` instead of `question_id` with no reference to the `foreign_type` of `taggable_type`:\r\n\r\n```ruby\r\nPaperTrail::VersionAssociation.create(\r\n  :version_id => version.id,\r\n  :foreign_key_name => assoc.foreign_key,\r\n  :foreign_key_id => self.send(assoc.foreign_key)\r\n)\r\n```\r\n\r\nAny thoughts or input?  I could very well just be doing something wrong, or perhaps there is no working path for polymorphic associations at this time."},"comment":{"url":"https://api.github.com/repos/airblade/paper_trail/issues/comments/72872870","html_url":"https://github.com/airblade/paper_trail/issues/474#issuecomment-72872870","issue_url":"https://api.github.com/repos/airblade/paper_trail/issues/474","id":72872870,"user":{"login":"daniel-rikowski","id":1169363,"avatar_url":"https://avatars.githubusercontent.com/u/1169363?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-rikowski","html_url":"https://github.com/daniel-rikowski","followers_url":"https://api.github.com/users/daniel-rikowski/followers","following_url":"https://api.github.com/users/daniel-rikowski/following{/other_user}","gists_url":"https://api.github.com/users/daniel-rikowski/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-rikowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-rikowski/subscriptions","organizations_url":"https://api.github.com/users/daniel-rikowski/orgs","repos_url":"https://api.github.com/users/daniel-rikowski/repos","events_url":"https://api.github.com/users/daniel-rikowski/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-rikowski/received_events","type":"User","site_admin":false},"created_at":"2015-02-04T15:18:35Z","updated_at":"2015-02-04T15:18:35Z","body":"I encountered the same problem, too.\r\n\r\nI just wanted to add that if there weren't a `Taggable` constant available, `assoc.klass` would yield a \r\n`NameError: uninitialized constant Tagging::Taggable`.\r\n\r\nAs fas as I understand that is caused by a long-standing Rails bug which affects Rails 2.3 to 4.2 and is apparently hard to fix (https://github.com/rails/rails/issues/2386, https://github.com/rails/rails/issues/15833)\r\n\r\n"}}