{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/14417","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/14417/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/14417/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/14417/events","html_url":"https://github.com/laravel/framework/pull/14417","id":166883119,"number":14417,"title":"[5.1] Don't let relations override user-defined keys","user":{"login":"phroggyy","id":7256451,"avatar_url":"https://avatars.githubusercontent.com/u/7256451?v=3","gravatar_id":"","url":"https://api.github.com/users/phroggyy","html_url":"https://github.com/phroggyy","followers_url":"https://api.github.com/users/phroggyy/followers","following_url":"https://api.github.com/users/phroggyy/following{/other_user}","gists_url":"https://api.github.com/users/phroggyy/gists{/gist_id}","starred_url":"https://api.github.com/users/phroggyy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phroggyy/subscriptions","organizations_url":"https://api.github.com/users/phroggyy/orgs","repos_url":"https://api.github.com/users/phroggyy/repos","events_url":"https://api.github.com/users/phroggyy/events{/privacy}","received_events_url":"https://api.github.com/users/phroggyy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-07-21T18:11:35Z","updated_at":"2016-07-22T13:08:35Z","closed_at":"2016-07-22T13:02:47Z","pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/14417","html_url":"https://github.com/laravel/framework/pull/14417","diff_url":"https://github.com/laravel/framework/pull/14417.diff","patch_url":"https://github.com/laravel/framework/pull/14417.patch"},"body":"I think this Behat scenario expresses it clearest:\r\n\r\n```\r\nGiven that App\\Customer has a relationship method `fields`\r\nAnd that I manually set $customer->fields on an instance\r\nWhen I call $customer->toJson\r\nThen I expect to see the fields I added\r\n```\r\n\r\nWhat actually happens now is that because the model does `return array_merge($attributes, $this->relationsToArray());`, the arrayed relations will override any keys set manually by the user.\r\n\r\nTo clarify\r\n\r\n```\r\n$fields = [];\r\n\r\n$customer->fields = $fields\r\n\r\n$this->assertEquals($fields, $customer->fields);\r\n$this->assertEquals($fields, $customer->toArray['fields']);\r\n```\r\n\r\nIn the above, given there's a relationship method `fields()`, the first assert would succeed, but the second would fail, so there's an inconsistency in the returned result."},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/234539074","html_url":"https://github.com/laravel/framework/pull/14417#issuecomment-234539074","issue_url":"https://api.github.com/repos/laravel/framework/issues/14417","id":234539074,"user":{"login":"phroggyy","id":7256451,"avatar_url":"https://avatars.githubusercontent.com/u/7256451?v=3","gravatar_id":"","url":"https://api.github.com/users/phroggyy","html_url":"https://github.com/phroggyy","followers_url":"https://api.github.com/users/phroggyy/followers","following_url":"https://api.github.com/users/phroggyy/following{/other_user}","gists_url":"https://api.github.com/users/phroggyy/gists{/gist_id}","starred_url":"https://api.github.com/users/phroggyy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phroggyy/subscriptions","organizations_url":"https://api.github.com/users/phroggyy/orgs","repos_url":"https://api.github.com/users/phroggyy/repos","events_url":"https://api.github.com/users/phroggyy/events{/privacy}","received_events_url":"https://api.github.com/users/phroggyy/received_events","type":"User","site_admin":false},"created_at":"2016-07-22T13:08:35Z","updated_at":"2016-07-22T13:08:35Z","body":"@taylorotwell: in the developer's mind, aren't you just setting an\nattribute tho? Isn't the inconsistency a bit odd? I'd expect\n`$object->fields` to give me the same output as\n`$output->toArray()['fields']`\nOn Fri, 22 Jul 2016 at 15:03, Taylor Otwell <notifications@github.com>\nwrote:\n\n> Closed #14417 <https://github.com/laravel/framework/pull/14417>.\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/laravel/framework/pull/14417#event-731718489>, or mute\n> the thread\n> <https://github.com/notifications/unsubscribe-auth/AG65g-JKjLSCEXxUVWxv7OxGdVxvzIxRks5qYL-NgaJpZM4JSEWk>\n> .\n>\n"}}
{"actor":{"display_login":"phroggyy"}}