{"action":"created","comment":{"url":"https://api.github.com/repos/airblade/paper_trail/pulls/comments/39469981","id":39469981,"diff_hunk":"@@ -417,7 +417,14 @@ def reify_has_many_through(associations, model, options = {})\n       associations.each do |assoc|\n         next unless assoc.klass.paper_trail_enabled_for_model?\n         through_collection = model.send(assoc.options[:through])\n-        collection_keys = through_collection.map { |through_model| through_model.send(assoc.foreign_key) }\n+\n+        # if the association is a has_many association again, then call reify_has_manys for each through_collection\n+        if !assoc.source_reflection.belongs_to? && through_collection.present?\n+          through_collection.each { |through_model| reify_has_manys(through_model,options) }\n+          return","path":"lib/paper_trail/version_concern.rb","position":null,"original_position":9,"commit_id":"e0fd33eab5d12773729fa0d60385a251d82e5c84","original_commit_id":"aaac0eae519dce25813d8fc44559ab89581bc719","user":{"login":"theRealNG","id":5243592,"avatar_url":"https://avatars.githubusercontent.com/u/5243592?v=3","gravatar_id":"","url":"https://api.github.com/users/theRealNG","html_url":"https://github.com/theRealNG","followers_url":"https://api.github.com/users/theRealNG/followers","following_url":"https://api.github.com/users/theRealNG/following{/other_user}","gists_url":"https://api.github.com/users/theRealNG/gists{/gist_id}","starred_url":"https://api.github.com/users/theRealNG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theRealNG/subscriptions","organizations_url":"https://api.github.com/users/theRealNG/orgs","repos_url":"https://api.github.com/users/theRealNG/repos","events_url":"https://api.github.com/users/theRealNG/events{/privacy}","received_events_url":"https://api.github.com/users/theRealNG/received_events","type":"User","site_admin":false},"body":"Yup @batter you are right. Thanks @jaredbeck ","created_at":"2015-09-15T02:52:50Z","updated_at":"2015-09-15T02:52:50Z","html_url":"https://github.com/airblade/paper_trail/pull/596#discussion_r39469981","pull_request_url":"https://api.github.com/repos/airblade/paper_trail/pulls/596","_links":{"self":{"href":"https://api.github.com/repos/airblade/paper_trail/pulls/comments/39469981"},"html":{"href":"https://github.com/airblade/paper_trail/pull/596#discussion_r39469981"},"pull_request":{"href":"https://api.github.com/repos/airblade/paper_trail/pulls/596"}}},"pull_request":{"url":"https://api.github.com/repos/airblade/paper_trail/pulls/596","id":43659847,"html_url":"https://github.com/airblade/paper_trail/pull/596","diff_url":"https://github.com/airblade/paper_trail/pull/596.diff","patch_url":"https://github.com/airblade/paper_trail/pull/596.patch","issue_url":"https://api.github.com/repos/airblade/paper_trail/issues/596","number":596,"state":"open","locked":false,"title":"fix issue in #reify_has_many_through","user":{"login":"theRealNG","id":5243592,"avatar_url":"https://avatars.githubusercontent.com/u/5243592?v=3","gravatar_id":"","url":"https://api.github.com/users/theRealNG","html_url":"https://github.com/theRealNG","followers_url":"https://api.github.com/users/theRealNG/followers","following_url":"https://api.github.com/users/theRealNG/following{/other_user}","gists_url":"https://api.github.com/users/theRealNG/gists{/gist_id}","starred_url":"https://api.github.com/users/theRealNG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theRealNG/subscriptions","organizations_url":"https://api.github.com/users/theRealNG/orgs","repos_url":"https://api.github.com/users/theRealNG/repos","events_url":"https://api.github.com/users/theRealNG/events{/privacy}","received_events_url":"https://api.github.com/users/theRealNG/received_events","type":"User","site_admin":false},"body":"Fix for https://github.com/airblade/paper_trail/issues/590\r\n\r\nThe assoc.foreign_key holds true only when the association is as follows\r\n\r\n```ruby\r\nBook\r\nhas_many :authorships\r\nhas_many :authors, :through => :authorships\r\n\r\nAuthorships\r\nbelongs_to :book\r\nbelongs_to :author\r\n\r\nAuthor\r\nhas_many :authorships\r\nhas_many :books, :through => :authorships\r\n```\r\n\r\nIn this case the assoc.foreign_key and assoc.association_foreign_key are the same\r\n\r\nBut in the case of the following associations\r\n\r\n```ruby\r\nDocument\r\nhas_many :sections\r\nhas_many :paragraphs, :through => :sections\r\n\r\nSection\r\nbelongs_to :document\r\nhas_many :paragraphs\r\n\r\nParagraph\r\nbelongs_to :section\r\n```\r\n\r\nthe assoc.foreign_key and assoc.association_foreign_key are different and assoc.association_foreign_key gets the correct list of associated foreign_keys for the model.\r\n\r\nFor Ref: http://www.rubydoc.info/docs/rails/3.0.0/ActiveRecord%2FReflection%2FAssociationReflection%3Aassociation_foreign_key\r\n\r\nEDIT: \r\nWhen a nested has_many relation is present, using the \"reify_has_manys\" method to reify the has_many through associations.","created_at":"2015-08-28T18:53:17Z","updated_at":"2015-09-15T02:52:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6b5de7f69baf13b69eaa4dd9fa17a37452240988","assignee":null,"milestone":{"url":"https://api.github.com/repos/airblade/paper_trail/milestones/11","html_url":"https://github.com/airblade/paper_trail/milestones/4.1.0","labels_url":"https://api.github.com/repos/airblade/paper_trail/milestones/11/labels","id":1174164,"number":11,"title":"4.1.0","description":null,"creator":{"login":"jaredbeck","id":380809,"avatar_url":"https://avatars.githubusercontent.com/u/380809?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredbeck","html_url":"https://github.com/jaredbeck","followers_url":"https://api.github.com/users/jaredbeck/followers","following_url":"https://api.github.com/users/jaredbeck/following{/other_user}","gists_url":"https://api.github.com/users/jaredbeck/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredbeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredbeck/subscriptions","organizations_url":"https://api.github.com/users/jaredbeck/orgs","repos_url":"https://api.github.com/users/jaredbeck/repos","events_url":"https://api.github.com/users/jaredbeck/events{/privacy}","received_events_url":"https://api.github.com/users/jaredbeck/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":3,"state":"open","created_at":"2015-06-21T20:21:35Z","updated_at":"2015-09-13T19:59:47Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/airblade/paper_trail/pulls/596/commits","review_comments_url":"https://api.github.com/repos/airblade/paper_trail/pulls/596/comments","review_comment_url":"https://api.github.com/repos/airblade/paper_trail/pulls/comments{/number}","comments_url":"https://api.github.com/repos/airblade/paper_trail/issues/596/comments","statuses_url":"https://api.github.com/repos/airblade/paper_trail/statuses/e0fd33eab5d12773729fa0d60385a251d82e5c84","head":{"label":"theRealNG:issue#590","ref":"issue#590","sha":"e0fd33eab5d12773729fa0d60385a251d82e5c84","user":{"login":"theRealNG","id":5243592,"avatar_url":"https://avatars.githubusercontent.com/u/5243592?v=3","gravatar_id":"","url":"https://api.github.com/users/theRealNG","html_url":"https://github.com/theRealNG","followers_url":"https://api.github.com/users/theRealNG/followers","following_url":"https://api.github.com/users/theRealNG/following{/other_user}","gists_url":"https://api.github.com/users/theRealNG/gists{/gist_id}","starred_url":"https://api.github.com/users/theRealNG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theRealNG/subscriptions","organizations_url":"https://api.github.com/users/theRealNG/orgs","repos_url":"https://api.github.com/users/theRealNG/repos","events_url":"https://api.github.com/users/theRealNG/events{/privacy}","received_events_url":"https://api.github.com/users/theRealNG/received_events","type":"User","site_admin":false},"repo":{"id":41483987,"name":"paper_trail","full_name":"theRealNG/paper_trail","owner":{"login":"theRealNG","id":5243592,"avatar_url":"https://avatars.githubusercontent.com/u/5243592?v=3","gravatar_id":"","url":"https://api.github.com/users/theRealNG","html_url":"https://github.com/theRealNG","followers_url":"https://api.github.com/users/theRealNG/followers","following_url":"https://api.github.com/users/theRealNG/following{/other_user}","gists_url":"https://api.github.com/users/theRealNG/gists{/gist_id}","starred_url":"https://api.github.com/users/theRealNG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theRealNG/subscriptions","organizations_url":"https://api.github.com/users/theRealNG/orgs","repos_url":"https://api.github.com/users/theRealNG/repos","events_url":"https://api.github.com/users/theRealNG/events{/privacy}","received_events_url":"https://api.github.com/users/theRealNG/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/theRealNG/paper_trail","description":"Track changes to your models' data.  Good for auditing or versioning.","fork":true,"url":"https://api.github.com/repos/theRealNG/paper_trail","forks_url":"https://api.github.com/repos/theRealNG/paper_trail/forks","keys_url":"https://api.github.com/repos/theRealNG/paper_trail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theRealNG/paper_trail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theRealNG/paper_trail/teams","hooks_url":"https://api.github.com/repos/theRealNG/paper_trail/hooks","issue_events_url":"https://api.github.com/repos/theRealNG/paper_trail/issues/events{/number}","events_url":"https://api.github.com/repos/theRealNG/paper_trail/events","assignees_url":"https://api.github.com/repos/theRealNG/paper_trail/assignees{/user}","branches_url":"https://api.github.com/repos/theRealNG/paper_trail/branches{/branch}","tags_url":"https://api.github.com/repos/theRealNG/paper_trail/tags","blobs_url":"https://api.github.com/repos/theRealNG/paper_trail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theRealNG/paper_trail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theRealNG/paper_trail/git/refs{/sha}","trees_url":"https://api.github.com/repos/theRealNG/paper_trail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theRealNG/paper_trail/statuses/{sha}","languages_url":"https://api.github.com/repos/theRealNG/paper_trail/languages","stargazers_url":"https://api.github.com/repos/theRealNG/paper_trail/stargazers","contributors_url":"https://api.github.com/repos/theRealNG/paper_trail/contributors","subscribers_url":"https://api.github.com/repos/theRealNG/paper_trail/subscribers","subscription_url":"https://api.github.com/repos/theRealNG/paper_trail/subscription","commits_url":"https://api.github.com/repos/theRealNG/paper_trail/commits{/sha}","git_commits_url":"https://api.github.com/repos/theRealNG/paper_trail/git/commits{/sha}","comments_url":"https://api.github.com/repos/theRealNG/paper_trail/comments{/number}","issue_comment_url":"https://api.github.com/repos/theRealNG/paper_trail/issues/comments{/number}","contents_url":"https://api.github.com/repos/theRealNG/paper_trail/contents/{+path}","compare_url":"https://api.github.com/repos/theRealNG/paper_trail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theRealNG/paper_trail/merges","archive_url":"https://api.github.com/repos/theRealNG/paper_trail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theRealNG/paper_trail/downloads","issues_url":"https://api.github.com/repos/theRealNG/paper_trail/issues{/number}","pulls_url":"https://api.github.com/repos/theRealNG/paper_trail/pulls{/number}","milestones_url":"https://api.github.com/repos/theRealNG/paper_trail/milestones{/number}","notifications_url":"https://api.github.com/repos/theRealNG/paper_trail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theRealNG/paper_trail/labels{/name}","releases_url":"https://api.github.com/repos/theRealNG/paper_trail/releases{/id}","created_at":"2015-08-27T11:56:50Z","updated_at":"2015-08-27T11:56:51Z","pushed_at":"2015-09-15T02:50:28Z","git_url":"git://github.com/theRealNG/paper_trail.git","ssh_url":"git@github.com:theRealNG/paper_trail.git","clone_url":"https://github.com/theRealNG/paper_trail.git","svn_url":"https://github.com/theRealNG/paper_trail","homepage":"","size":1850,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"airblade:master","ref":"master","sha":"a1108a66d3593c275be25774458f9e1bf115756d","user":{"login":"airblade","id":7265,"avatar_url":"https://avatars.githubusercontent.com/u/7265?v=3","gravatar_id":"","url":"https://api.github.com/users/airblade","html_url":"https://github.com/airblade","followers_url":"https://api.github.com/users/airblade/followers","following_url":"https://api.github.com/users/airblade/following{/other_user}","gists_url":"https://api.github.com/users/airblade/gists{/gist_id}","starred_url":"https://api.github.com/users/airblade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/airblade/subscriptions","organizations_url":"https://api.github.com/users/airblade/orgs","repos_url":"https://api.github.com/users/airblade/repos","events_url":"https://api.github.com/users/airblade/events{/privacy}","received_events_url":"https://api.github.com/users/airblade/received_events","type":"User","site_admin":false},"repo":{"id":211588,"name":"paper_trail","full_name":"airblade/paper_trail","owner":{"login":"airblade","id":7265,"avatar_url":"https://avatars.githubusercontent.com/u/7265?v=3","gravatar_id":"","url":"https://api.github.com/users/airblade","html_url":"https://github.com/airblade","followers_url":"https://api.github.com/users/airblade/followers","following_url":"https://api.github.com/users/airblade/following{/other_user}","gists_url":"https://api.github.com/users/airblade/gists{/gist_id}","starred_url":"https://api.github.com/users/airblade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/airblade/subscriptions","organizations_url":"https://api.github.com/users/airblade/orgs","repos_url":"https://api.github.com/users/airblade/repos","events_url":"https://api.github.com/users/airblade/events{/privacy}","received_events_url":"https://api.github.com/users/airblade/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/airblade/paper_trail","description":"Track changes to your models' data.  Good for auditing or versioning.","fork":false,"url":"https://api.github.com/repos/airblade/paper_trail","forks_url":"https://api.github.com/repos/airblade/paper_trail/forks","keys_url":"https://api.github.com/repos/airblade/paper_trail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/airblade/paper_trail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/airblade/paper_trail/teams","hooks_url":"https://api.github.com/repos/airblade/paper_trail/hooks","issue_events_url":"https://api.github.com/repos/airblade/paper_trail/issues/events{/number}","events_url":"https://api.github.com/repos/airblade/paper_trail/events","assignees_url":"https://api.github.com/repos/airblade/paper_trail/assignees{/user}","branches_url":"https://api.github.com/repos/airblade/paper_trail/branches{/branch}","tags_url":"https://api.github.com/repos/airblade/paper_trail/tags","blobs_url":"https://api.github.com/repos/airblade/paper_trail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/airblade/paper_trail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/airblade/paper_trail/git/refs{/sha}","trees_url":"https://api.github.com/repos/airblade/paper_trail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/airblade/paper_trail/statuses/{sha}","languages_url":"https://api.github.com/repos/airblade/paper_trail/languages","stargazers_url":"https://api.github.com/repos/airblade/paper_trail/stargazers","contributors_url":"https://api.github.com/repos/airblade/paper_trail/contributors","subscribers_url":"https://api.github.com/repos/airblade/paper_trail/subscribers","subscription_url":"https://api.github.com/repos/airblade/paper_trail/subscription","commits_url":"https://api.github.com/repos/airblade/paper_trail/commits{/sha}","git_commits_url":"https://api.github.com/repos/airblade/paper_trail/git/commits{/sha}","comments_url":"https://api.github.com/repos/airblade/paper_trail/comments{/number}","issue_comment_url":"https://api.github.com/repos/airblade/paper_trail/issues/comments{/number}","contents_url":"https://api.github.com/repos/airblade/paper_trail/contents/{+path}","compare_url":"https://api.github.com/repos/airblade/paper_trail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/airblade/paper_trail/merges","archive_url":"https://api.github.com/repos/airblade/paper_trail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/airblade/paper_trail/downloads","issues_url":"https://api.github.com/repos/airblade/paper_trail/issues{/number}","pulls_url":"https://api.github.com/repos/airblade/paper_trail/pulls{/number}","milestones_url":"https://api.github.com/repos/airblade/paper_trail/milestones{/number}","notifications_url":"https://api.github.com/repos/airblade/paper_trail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/airblade/paper_trail/labels{/name}","releases_url":"https://api.github.com/repos/airblade/paper_trail/releases{/id}","created_at":"2009-05-27T15:20:55Z","updated_at":"2015-09-13T11:49:40Z","pushed_at":"2015-09-15T02:50:29Z","git_url":"git://github.com/airblade/paper_trail.git","ssh_url":"git@github.com:airblade/paper_trail.git","clone_url":"https://github.com/airblade/paper_trail.git","svn_url":"https://github.com/airblade/paper_trail","homepage":"","size":4930,"stargazers_count":3554,"watchers_count":3554,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":473,"mirror_url":null,"open_issues_count":19,"forks":473,"open_issues":19,"watchers":3554,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/airblade/paper_trail/pulls/596"},"html":{"href":"https://github.com/airblade/paper_trail/pull/596"},"issue":{"href":"https://api.github.com/repos/airblade/paper_trail/issues/596"},"comments":{"href":"https://api.github.com/repos/airblade/paper_trail/issues/596/comments"},"review_comments":{"href":"https://api.github.com/repos/airblade/paper_trail/pulls/596/comments"},"review_comment":{"href":"https://api.github.com/repos/airblade/paper_trail/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/airblade/paper_trail/pulls/596/commits"},"statuses":{"href":"https://api.github.com/repos/airblade/paper_trail/statuses/e0fd33eab5d12773729fa0d60385a251d82e5c84"}}}}