{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/27510","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/27510/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/27510/comments","events_url":"https://api.github.com/repos/rails/rails/issues/27510/events","html_url":"https://github.com/rails/rails/issues/27510","id":198147877,"number":27510,"title":"5.0.0.1 -> 5.0.1 `pluck` returns data of unsaved association records","user":{"login":"dsander","id":20943,"avatar_url":"https://avatars.githubusercontent.com/u/20943?v=3","gravatar_id":"","url":"https://api.github.com/users/dsander","html_url":"https://github.com/dsander","followers_url":"https://api.github.com/users/dsander/followers","following_url":"https://api.github.com/users/dsander/following{/other_user}","gists_url":"https://api.github.com/users/dsander/gists{/gist_id}","starred_url":"https://api.github.com/users/dsander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsander/subscriptions","organizations_url":"https://api.github.com/users/dsander/orgs","repos_url":"https://api.github.com/users/dsander/repos","events_url":"https://api.github.com/users/dsander/events{/privacy}","received_events_url":"https://api.github.com/users/dsander/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-30T13:32:20Z","updated_at":"2016-12-30T16:02:58Z","closed_at":"2016-12-30T14:25:22Z","body":"`pluck` now returns data from new records if the association is loaded. \r\nPull request that changed the behavior: https://github.com/rails/rails/pull/25976\r\n\r\n### Steps to reproduce\r\n\r\n```\r\nassociations = current_user.associations.load;\r\nnew = associations.build\r\nids = current_user.associations.pluck(:id)\r\n=> [...., nil]\r\n```\r\n\r\n### Expected behavior\r\n\r\n`pluck` should not return data of unsaved records. \r\n\r\n### System configuration\r\n**Rails version**: 5.0.1\r\n\r\n**Ruby version**: 2.3.3\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/269788033","html_url":"https://github.com/rails/rails/issues/27510#issuecomment-269788033","issue_url":"https://api.github.com/repos/rails/rails/issues/27510","id":269788033,"user":{"login":"matthewd","id":1034,"avatar_url":"https://avatars.githubusercontent.com/u/1034?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewd","html_url":"https://github.com/matthewd","followers_url":"https://api.github.com/users/matthewd/followers","following_url":"https://api.github.com/users/matthewd/following{/other_user}","gists_url":"https://api.github.com/users/matthewd/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewd/subscriptions","organizations_url":"https://api.github.com/users/matthewd/orgs","repos_url":"https://api.github.com/users/matthewd/repos","events_url":"https://api.github.com/users/matthewd/events{/privacy}","received_events_url":"https://api.github.com/users/matthewd/received_events","type":"User","site_admin":false},"created_at":"2016-12-30T16:02:58Z","updated_at":"2016-12-30T16:02:58Z","body":"Sure!\r\n\r\nNote that on a loaded relation, it'll use the loaded records for `pluck(:some_attribute)`, but still has to go to the DB for `pluck('arbitrary sql')`:\r\n\r\n```\r\nPerson.pluck(:id) => SELECT id FROM people\r\nPerson.load.pluck(:id) => SELECT * FROM people\r\nPerson.to_a.pluck(:id) => SELECT * FROM people\r\n\r\nPerson.pluck('id * 2') => SELECT id * 2 FROM people\r\nPerson.load.pluck('id * 2') => SELECT * FROM people; SELECT id * 2 FROM people\r\nPerson.to_a.pluck('id * 2') => SELECT * FROM people; exception\r\n```\r\n\r\n(In the context of this issue, that means different arguments to pluck can actually give different numbers of results on the same object. Maybe we should raise if pluck needs to hit the database and there are unsaved records in the association. 🤔)"}}
{"actor":{"display_login":"matthewd"}}