{"action":"created","issue":{"url":"https://api.github.com/repos/cloudcreativity/laravel-json-api/issues/222","repository_url":"https://api.github.com/repos/cloudcreativity/laravel-json-api","labels_url":"https://api.github.com/repos/cloudcreativity/laravel-json-api/issues/222/labels{/name}","comments_url":"https://api.github.com/repos/cloudcreativity/laravel-json-api/issues/222/comments","events_url":"https://api.github.com/repos/cloudcreativity/laravel-json-api/issues/222/events","html_url":"https://github.com/cloudcreativity/laravel-json-api/issues/222","id":357123416,"node_id":"MDU6SXNzdWUzNTcxMjM0MTY=","number":222,"title":"Attempt to add existing resource to 'hasMany' relationship via POST method attempts database re-insertion, contrary to spec","user":{"login":"SirLamer","id":1343049,"node_id":"MDQ6VXNlcjEzNDMwNDk=","avatar_url":"https://avatars0.githubusercontent.com/u/1343049?v=4","gravatar_id":"","url":"https://api.github.com/users/SirLamer","html_url":"https://github.com/SirLamer","followers_url":"https://api.github.com/users/SirLamer/followers","following_url":"https://api.github.com/users/SirLamer/following{/other_user}","gists_url":"https://api.github.com/users/SirLamer/gists{/gist_id}","starred_url":"https://api.github.com/users/SirLamer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SirLamer/subscriptions","organizations_url":"https://api.github.com/users/SirLamer/orgs","repos_url":"https://api.github.com/users/SirLamer/repos","events_url":"https://api.github.com/users/SirLamer/events{/privacy}","received_events_url":"https://api.github.com/users/SirLamer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-05T08:38:57Z","updated_at":"2018-09-05T08:48:45Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Testing with laravel-json-api v1.0.0-beta.2 and Laravel v5.5\r\n\r\nFrom JSON API spec here:\r\nhttp://jsonapi.org/format/#crud-updating-to-many-relationships\r\n```\r\nIf a client makes a POST request to a URL from a relationship link, the server MUST add the specified members to the relationship unless they are already present. If a given type and id is already in the relationship, the server MUST NOT add it again.\r\n\r\nNote: This matches the semantics of databases that use foreign keys for has-many relationships. Document-based storage should check the has-many relationship before appending to avoid duplicates.\r\n\r\nIf all of the specified resources can be added to, or are already present in, the relationship then the server MUST return a successful response.\r\n\r\nNote: This approach ensures that a request is successful if the server’s state matches the requested state, and helps avoid pointless race conditions caused by multiple clients making the same changes to a relationship.\r\n```\r\n\r\nWhen trying to add a child model to a 'hasMany' relationship where that child is already a member of the relationship, the API should return a \"SUCCESS\" response and behave as though the relationship addition was successful. This implies that the API software must first perform a check to see if that child is already a relationship member. This appears to not be happening, and as a result the item is added to the relationship again. A well-designed database should be enforcing a 'UNIQUE' requirement on the database-level, which would generate an error and return a 500 Internal Server Error response. Absent of that, the item would be added to the database again and report success but will have corrupted the relationship with duplicate membership records for one item."},"comment":{"url":"https://api.github.com/repos/cloudcreativity/laravel-json-api/issues/comments/418651016","html_url":"https://github.com/cloudcreativity/laravel-json-api/issues/222#issuecomment-418651016","issue_url":"https://api.github.com/repos/cloudcreativity/laravel-json-api/issues/222","id":418651016,"node_id":"MDEyOklzc3VlQ29tbWVudDQxODY1MTAxNg==","user":{"login":"lindyhopchris","id":4464333,"node_id":"MDQ6VXNlcjQ0NjQzMzM=","avatar_url":"https://avatars0.githubusercontent.com/u/4464333?v=4","gravatar_id":"","url":"https://api.github.com/users/lindyhopchris","html_url":"https://github.com/lindyhopchris","followers_url":"https://api.github.com/users/lindyhopchris/followers","following_url":"https://api.github.com/users/lindyhopchris/following{/other_user}","gists_url":"https://api.github.com/users/lindyhopchris/gists{/gist_id}","starred_url":"https://api.github.com/users/lindyhopchris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lindyhopchris/subscriptions","organizations_url":"https://api.github.com/users/lindyhopchris/orgs","repos_url":"https://api.github.com/users/lindyhopchris/repos","events_url":"https://api.github.com/users/lindyhopchris/events{/privacy}","received_events_url":"https://api.github.com/users/lindyhopchris/received_events","type":"User","site_admin":false},"created_at":"2018-09-05T08:48:45Z","updated_at":"2018-09-05T08:48:45Z","author_association":"MEMBER","body":"Will add some test scenarios for this. Internally I'm just using the Laravel methods on the relationship to update it, so it's probable that those don't work in the way that the JSON API spec envisages... so will have to write something to make sure only new ids are pushed into the relationship.\r\n\r\nThanks for reporting."}}
{"actor":{"display_login":"lindyhopchris"}}