{"action":"created","issue":{"url":"https://api.github.com/repos/sbarre/eloquent-versioned/issues/17","labels_url":"https://api.github.com/repos/sbarre/eloquent-versioned/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/sbarre/eloquent-versioned/issues/17/comments","events_url":"https://api.github.com/repos/sbarre/eloquent-versioned/issues/17/events","html_url":"https://github.com/sbarre/eloquent-versioned/issues/17","id":92499027,"number":17,"title":"function getNextModelId() function will cause issues","user":{"login":"Towerful","id":2766601,"avatar_url":"https://avatars.githubusercontent.com/u/2766601?v=3","gravatar_id":"","url":"https://api.github.com/users/Towerful","html_url":"https://github.com/Towerful","followers_url":"https://api.github.com/users/Towerful/followers","following_url":"https://api.github.com/users/Towerful/following{/other_user}","gists_url":"https://api.github.com/users/Towerful/gists{/gist_id}","starred_url":"https://api.github.com/users/Towerful/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Towerful/subscriptions","organizations_url":"https://api.github.com/users/Towerful/orgs","repos_url":"https://api.github.com/users/Towerful/repos","events_url":"https://api.github.com/users/Towerful/events{/privacy}","received_events_url":"https://api.github.com/users/Towerful/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-01T22:31:25Z","updated_at":"2015-07-01T22:51:48Z","closed_at":"2015-07-01T22:51:48Z","body":"so,  \r\ncurrent version ( 0.0.7 )  \r\nin the Trait ~line 183 ( https://github.com/sbarre/eloquent-versioned/blob/5cccfa9f29a230945697fd290a66c197bb659e7f/src/Traits/Versioned.php#L255 )\r\n\r\nyou are getting the Max of the ID column.  \r\nWhat happens if a record is inserted elsewhere between the call and the return of this function (and final saving of this model)?  \r\nThe model_id will reference the wrong record.  \r\nOr, if the latest model (eg `id: 177`, previous model being `id: 176`) has been deleted at some point, return will be `177`, but MySQL autoinc will set the model `id:178`\r\n\r\nWould it not be better to save first, then self-reference the new model & update? at the expense of an extra DB query.. \r\nI would love to set up a pull-request, but I have no idea how!"},"comment":{"url":"https://api.github.com/repos/sbarre/eloquent-versioned/issues/comments/117844737","html_url":"https://github.com/sbarre/eloquent-versioned/issues/17#issuecomment-117844737","issue_url":"https://api.github.com/repos/sbarre/eloquent-versioned/issues/17","id":117844737,"user":{"login":"Towerful","id":2766601,"avatar_url":"https://avatars.githubusercontent.com/u/2766601?v=3","gravatar_id":"","url":"https://api.github.com/users/Towerful","html_url":"https://github.com/Towerful","followers_url":"https://api.github.com/users/Towerful/followers","following_url":"https://api.github.com/users/Towerful/following{/other_user}","gists_url":"https://api.github.com/users/Towerful/gists{/gist_id}","starred_url":"https://api.github.com/users/Towerful/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Towerful/subscriptions","organizations_url":"https://api.github.com/users/Towerful/orgs","repos_url":"https://api.github.com/users/Towerful/repos","events_url":"https://api.github.com/users/Towerful/events{/privacy}","received_events_url":"https://api.github.com/users/Towerful/received_events","type":"User","site_admin":false},"created_at":"2015-07-01T22:51:48Z","updated_at":"2015-07-01T22:51:48Z","body":"Yes, I've seen that. sorry, I didn't realize that hadn't been merged.  \r\nThis issue has also been discussed in issue #8 , altho tangentially."}}