{"action":"created","comment":{"url":"https://api.github.com/repos/solidusio/solidus/pulls/comments/76696491","id":76696491,"diff_hunk":"@@ -6,18 +6,18 @@ class Spree::UnitCancel < Spree::Base\n   DEFAULT_REASON = 'Cancel'\n \n   belongs_to :inventory_unit\n-  has_one :adjustment, as: :source, dependent: :destroy\n+  has_many :adjustments, as: :source, dependent: :destroy\n \n   validates :inventory_unit, presence: true\n \n   # Creates necessary cancel adjustments for the line item.\n   def adjust!\n-    raise \"Adjustment is already created\" if adjustment\n+    raise \"Adjustment is already created\" if adjustments.exists?\n \n     amount = compute_amount(inventory_unit.line_item)\n \n-    create_adjustment!(\n-      adjustable: inventory_unit.line_item,\n+    inventory_unit.line_item.adjustments.create!(","path":"core/app/models/spree/unit_cancel.rb","position":18,"original_position":18,"commit_id":"9ad5b2381f05133b12fc3283b097ccef925ca0ab","original_commit_id":"9ad5b2381f05133b12fc3283b097ccef925ca0ab","user":{"login":"jhawthorn","id":131752,"avatar_url":"https://avatars.githubusercontent.com/u/131752?v=3","gravatar_id":"","url":"https://api.github.com/users/jhawthorn","html_url":"https://github.com/jhawthorn","followers_url":"https://api.github.com/users/jhawthorn/followers","following_url":"https://api.github.com/users/jhawthorn/following{/other_user}","gists_url":"https://api.github.com/users/jhawthorn/gists{/gist_id}","starred_url":"https://api.github.com/users/jhawthorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhawthorn/subscriptions","organizations_url":"https://api.github.com/users/jhawthorn/orgs","repos_url":"https://api.github.com/users/jhawthorn/repos","events_url":"https://api.github.com/users/jhawthorn/events{/privacy}","received_events_url":"https://api.github.com/users/jhawthorn/received_events","type":"User","site_admin":false},"body":"Alternatively, I think this could be.\r\n\r\n```\r\nself.adjustment = inventory_unit.line_item.adjustments.create!(\r\n```\r\n\r\nThis should keep both associations fresh without performing an extra query (no query run since source will already be set correctly). This avoids the need to change the `has_one` to a `has_many`","created_at":"2016-08-29T22:03:35Z","updated_at":"2016-08-29T22:03:35Z","html_url":"https://github.com/solidusio/solidus/pull/1401#discussion_r76696491","pull_request_url":"https://api.github.com/repos/solidusio/solidus/pulls/1401","_links":{"self":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/comments/76696491"},"html":{"href":"https://github.com/solidusio/solidus/pull/1401#discussion_r76696491"},"pull_request":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/1401"}}},"pull_request":{"url":"https://api.github.com/repos/solidusio/solidus/pulls/1401","id":82533270,"html_url":"https://github.com/solidusio/solidus/pull/1401","diff_url":"https://github.com/solidusio/solidus/pull/1401.diff","patch_url":"https://github.com/solidusio/solidus/pull/1401.patch","issue_url":"https://api.github.com/repos/solidusio/solidus/issues/1401","number":1401,"state":"open","locked":false,"title":"Use in-memory objects for adjustments in ItemAdjustments","user":{"login":"jordan-brough","id":23050,"avatar_url":"https://avatars.githubusercontent.com/u/23050?v=3","gravatar_id":"","url":"https://api.github.com/users/jordan-brough","html_url":"https://github.com/jordan-brough","followers_url":"https://api.github.com/users/jordan-brough/followers","following_url":"https://api.github.com/users/jordan-brough/following{/other_user}","gists_url":"https://api.github.com/users/jordan-brough/gists{/gist_id}","starred_url":"https://api.github.com/users/jordan-brough/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordan-brough/subscriptions","organizations_url":"https://api.github.com/users/jordan-brough/orgs","repos_url":"https://api.github.com/users/jordan-brough/repos","events_url":"https://api.github.com/users/jordan-brough/events{/privacy}","received_events_url":"https://api.github.com/users/jordan-brough/received_events","type":"User","site_admin":false},"body":"See individual commits.\r\n\r\nThis avoids extra queries and should improve performance.\r\n\r\nIt also should make refactoring easier without adding extra queries,\r\nincluding some upcoming tax-refactoring I'm working on.\r\n\r\nThe two primary commits are these:\r\n\r\n- \"Automatically update `adjustments` relationships\" - a workaround for backward-compatibility\r\n- \"Use in-memory objects for adjustments in ItemAdjustments\" - to actually start using in-memory objects\r\n\r\nI'm not super happy with the above workaround, but I couldn't think of a better option.  Also, it makes me nervous that we need a workaround like that in the first place -- it seems like this could be fragile.  See, for example, the \"Don't use all_adjustments in OrderAdjuster\" commit.  Using `all_adjustments` in the \"wrong\" way can result in outdated in-memory objects and thus incorrect calculations.\r\n\r\nRelates to https://github.com/solidusio/solidus/issues/1252 and previous work done in https://github.com/solidusio/solidus/pull/1356, https://github.com/solidusio/solidus/pull/1389, and https://github.com/solidusio/solidus/pull/1400.","created_at":"2016-08-24T12:31:27Z","updated_at":"2016-08-29T22:03:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"431ac89d957890b2dfba8dfa48f6a11d239354ef","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/solidusio/solidus/milestones/7","html_url":"https://github.com/solidusio/solidus/milestones/1.4.0","labels_url":"https://api.github.com/repos/solidusio/solidus/milestones/7/labels","id":1847710,"number":7,"title":"1.4.0","description":"","creator":{"login":"jhawthorn","id":131752,"avatar_url":"https://avatars.githubusercontent.com/u/131752?v=3","gravatar_id":"","url":"https://api.github.com/users/jhawthorn","html_url":"https://github.com/jhawthorn","followers_url":"https://api.github.com/users/jhawthorn/followers","following_url":"https://api.github.com/users/jhawthorn/following{/other_user}","gists_url":"https://api.github.com/users/jhawthorn/gists{/gist_id}","starred_url":"https://api.github.com/users/jhawthorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhawthorn/subscriptions","organizations_url":"https://api.github.com/users/jhawthorn/orgs","repos_url":"https://api.github.com/users/jhawthorn/repos","events_url":"https://api.github.com/users/jhawthorn/events{/privacy}","received_events_url":"https://api.github.com/users/jhawthorn/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":7,"state":"open","created_at":"2016-06-24T19:57:25Z","updated_at":"2016-08-29T12:51:23Z","due_on":"2016-08-15T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/solidusio/solidus/pulls/1401/commits","review_comments_url":"https://api.github.com/repos/solidusio/solidus/pulls/1401/comments","review_comment_url":"https://api.github.com/repos/solidusio/solidus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/solidusio/solidus/issues/1401/comments","statuses_url":"https://api.github.com/repos/solidusio/solidus/statuses/9ad5b2381f05133b12fc3283b097ccef925ca0ab","head":{"label":"jordan-brough:in-memory-objects-in-item-adjustments","ref":"in-memory-objects-in-item-adjustments","sha":"9ad5b2381f05133b12fc3283b097ccef925ca0ab","user":{"login":"jordan-brough","id":23050,"avatar_url":"https://avatars.githubusercontent.com/u/23050?v=3","gravatar_id":"","url":"https://api.github.com/users/jordan-brough","html_url":"https://github.com/jordan-brough","followers_url":"https://api.github.com/users/jordan-brough/followers","following_url":"https://api.github.com/users/jordan-brough/following{/other_user}","gists_url":"https://api.github.com/users/jordan-brough/gists{/gist_id}","starred_url":"https://api.github.com/users/jordan-brough/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordan-brough/subscriptions","organizations_url":"https://api.github.com/users/jordan-brough/orgs","repos_url":"https://api.github.com/users/jordan-brough/repos","events_url":"https://api.github.com/users/jordan-brough/events{/privacy}","received_events_url":"https://api.github.com/users/jordan-brough/received_events","type":"User","site_admin":false},"repo":{"id":37918071,"name":"solidus","full_name":"jordan-brough/solidus","owner":{"login":"jordan-brough","id":23050,"avatar_url":"https://avatars.githubusercontent.com/u/23050?v=3","gravatar_id":"","url":"https://api.github.com/users/jordan-brough","html_url":"https://github.com/jordan-brough","followers_url":"https://api.github.com/users/jordan-brough/followers","following_url":"https://api.github.com/users/jordan-brough/following{/other_user}","gists_url":"https://api.github.com/users/jordan-brough/gists{/gist_id}","starred_url":"https://api.github.com/users/jordan-brough/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordan-brough/subscriptions","organizations_url":"https://api.github.com/users/jordan-brough/orgs","repos_url":"https://api.github.com/users/jordan-brough/repos","events_url":"https://api.github.com/users/jordan-brough/events{/privacy}","received_events_url":"https://api.github.com/users/jordan-brough/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jordan-brough/solidus","description":"Solidus e-commerce system","fork":true,"url":"https://api.github.com/repos/jordan-brough/solidus","forks_url":"https://api.github.com/repos/jordan-brough/solidus/forks","keys_url":"https://api.github.com/repos/jordan-brough/solidus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jordan-brough/solidus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jordan-brough/solidus/teams","hooks_url":"https://api.github.com/repos/jordan-brough/solidus/hooks","issue_events_url":"https://api.github.com/repos/jordan-brough/solidus/issues/events{/number}","events_url":"https://api.github.com/repos/jordan-brough/solidus/events","assignees_url":"https://api.github.com/repos/jordan-brough/solidus/assignees{/user}","branches_url":"https://api.github.com/repos/jordan-brough/solidus/branches{/branch}","tags_url":"https://api.github.com/repos/jordan-brough/solidus/tags","blobs_url":"https://api.github.com/repos/jordan-brough/solidus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jordan-brough/solidus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jordan-brough/solidus/git/refs{/sha}","trees_url":"https://api.github.com/repos/jordan-brough/solidus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jordan-brough/solidus/statuses/{sha}","languages_url":"https://api.github.com/repos/jordan-brough/solidus/languages","stargazers_url":"https://api.github.com/repos/jordan-brough/solidus/stargazers","contributors_url":"https://api.github.com/repos/jordan-brough/solidus/contributors","subscribers_url":"https://api.github.com/repos/jordan-brough/solidus/subscribers","subscription_url":"https://api.github.com/repos/jordan-brough/solidus/subscription","commits_url":"https://api.github.com/repos/jordan-brough/solidus/commits{/sha}","git_commits_url":"https://api.github.com/repos/jordan-brough/solidus/git/commits{/sha}","comments_url":"https://api.github.com/repos/jordan-brough/solidus/comments{/number}","issue_comment_url":"https://api.github.com/repos/jordan-brough/solidus/issues/comments{/number}","contents_url":"https://api.github.com/repos/jordan-brough/solidus/contents/{+path}","compare_url":"https://api.github.com/repos/jordan-brough/solidus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jordan-brough/solidus/merges","archive_url":"https://api.github.com/repos/jordan-brough/solidus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jordan-brough/solidus/downloads","issues_url":"https://api.github.com/repos/jordan-brough/solidus/issues{/number}","pulls_url":"https://api.github.com/repos/jordan-brough/solidus/pulls{/number}","milestones_url":"https://api.github.com/repos/jordan-brough/solidus/milestones{/number}","notifications_url":"https://api.github.com/repos/jordan-brough/solidus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jordan-brough/solidus/labels{/name}","releases_url":"https://api.github.com/repos/jordan-brough/solidus/releases{/id}","deployments_url":"https://api.github.com/repos/jordan-brough/solidus/deployments","created_at":"2015-06-23T12:36:58Z","updated_at":"2016-08-16T17:39:55Z","pushed_at":"2016-08-26T17:24:06Z","git_url":"git://github.com/jordan-brough/solidus.git","ssh_url":"git@github.com:jordan-brough/solidus.git","clone_url":"https://github.com/jordan-brough/solidus.git","svn_url":"https://github.com/jordan-brough/solidus","homepage":"","size":68449,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"solidusio:master","ref":"master","sha":"065657fed332aa3754acc33f9d2546ff53b01335","user":{"login":"solidusio","id":11045486,"avatar_url":"https://avatars.githubusercontent.com/u/11045486?v=3","gravatar_id":"","url":"https://api.github.com/users/solidusio","html_url":"https://github.com/solidusio","followers_url":"https://api.github.com/users/solidusio/followers","following_url":"https://api.github.com/users/solidusio/following{/other_user}","gists_url":"https://api.github.com/users/solidusio/gists{/gist_id}","starred_url":"https://api.github.com/users/solidusio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solidusio/subscriptions","organizations_url":"https://api.github.com/users/solidusio/orgs","repos_url":"https://api.github.com/users/solidusio/repos","events_url":"https://api.github.com/users/solidusio/events{/privacy}","received_events_url":"https://api.github.com/users/solidusio/received_events","type":"Organization","site_admin":false},"repo":{"id":30985840,"name":"solidus","full_name":"solidusio/solidus","owner":{"login":"solidusio","id":11045486,"avatar_url":"https://avatars.githubusercontent.com/u/11045486?v=3","gravatar_id":"","url":"https://api.github.com/users/solidusio","html_url":"https://github.com/solidusio","followers_url":"https://api.github.com/users/solidusio/followers","following_url":"https://api.github.com/users/solidusio/following{/other_user}","gists_url":"https://api.github.com/users/solidusio/gists{/gist_id}","starred_url":"https://api.github.com/users/solidusio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solidusio/subscriptions","organizations_url":"https://api.github.com/users/solidusio/orgs","repos_url":"https://api.github.com/users/solidusio/repos","events_url":"https://api.github.com/users/solidusio/events{/privacy}","received_events_url":"https://api.github.com/users/solidusio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/solidusio/solidus","description":"Solidus, Rails eCommerce System","fork":false,"url":"https://api.github.com/repos/solidusio/solidus","forks_url":"https://api.github.com/repos/solidusio/solidus/forks","keys_url":"https://api.github.com/repos/solidusio/solidus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solidusio/solidus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solidusio/solidus/teams","hooks_url":"https://api.github.com/repos/solidusio/solidus/hooks","issue_events_url":"https://api.github.com/repos/solidusio/solidus/issues/events{/number}","events_url":"https://api.github.com/repos/solidusio/solidus/events","assignees_url":"https://api.github.com/repos/solidusio/solidus/assignees{/user}","branches_url":"https://api.github.com/repos/solidusio/solidus/branches{/branch}","tags_url":"https://api.github.com/repos/solidusio/solidus/tags","blobs_url":"https://api.github.com/repos/solidusio/solidus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solidusio/solidus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solidusio/solidus/git/refs{/sha}","trees_url":"https://api.github.com/repos/solidusio/solidus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solidusio/solidus/statuses/{sha}","languages_url":"https://api.github.com/repos/solidusio/solidus/languages","stargazers_url":"https://api.github.com/repos/solidusio/solidus/stargazers","contributors_url":"https://api.github.com/repos/solidusio/solidus/contributors","subscribers_url":"https://api.github.com/repos/solidusio/solidus/subscribers","subscription_url":"https://api.github.com/repos/solidusio/solidus/subscription","commits_url":"https://api.github.com/repos/solidusio/solidus/commits{/sha}","git_commits_url":"https://api.github.com/repos/solidusio/solidus/git/commits{/sha}","comments_url":"https://api.github.com/repos/solidusio/solidus/comments{/number}","issue_comment_url":"https://api.github.com/repos/solidusio/solidus/issues/comments{/number}","contents_url":"https://api.github.com/repos/solidusio/solidus/contents/{+path}","compare_url":"https://api.github.com/repos/solidusio/solidus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solidusio/solidus/merges","archive_url":"https://api.github.com/repos/solidusio/solidus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solidusio/solidus/downloads","issues_url":"https://api.github.com/repos/solidusio/solidus/issues{/number}","pulls_url":"https://api.github.com/repos/solidusio/solidus/pulls{/number}","milestones_url":"https://api.github.com/repos/solidusio/solidus/milestones{/number}","notifications_url":"https://api.github.com/repos/solidusio/solidus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solidusio/solidus/labels{/name}","releases_url":"https://api.github.com/repos/solidusio/solidus/releases{/id}","deployments_url":"https://api.github.com/repos/solidusio/solidus/deployments","created_at":"2015-02-18T20:41:58Z","updated_at":"2016-08-29T07:29:35Z","pushed_at":"2016-08-29T21:41:52Z","git_url":"git://github.com/solidusio/solidus.git","ssh_url":"git@github.com:solidusio/solidus.git","clone_url":"https://github.com/solidusio/solidus.git","svn_url":"https://github.com/solidusio/solidus","homepage":"https://solidus.io/","size":70643,"stargazers_count":1055,"watchers_count":1055,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":326,"mirror_url":null,"open_issues_count":159,"forks":326,"open_issues":159,"watchers":1055,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/1401"},"html":{"href":"https://github.com/solidusio/solidus/pull/1401"},"issue":{"href":"https://api.github.com/repos/solidusio/solidus/issues/1401"},"comments":{"href":"https://api.github.com/repos/solidusio/solidus/issues/1401/comments"},"review_comments":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/1401/comments"},"review_comment":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/1401/commits"},"statuses":{"href":"https://api.github.com/repos/solidusio/solidus/statuses/9ad5b2381f05133b12fc3283b097ccef925ca0ab"}}}}
{"actor":{"display_login":"jhawthorn"}}