{"action":"opened","issue":{"url":"https://api.github.com/repos/contao/core/issues/8608","repository_url":"https://api.github.com/repos/contao/core","labels_url":"https://api.github.com/repos/contao/core/issues/8608/labels{/name}","comments_url":"https://api.github.com/repos/contao/core/issues/8608/comments","events_url":"https://api.github.com/repos/contao/core/issues/8608/events","html_url":"https://github.com/contao/core/issues/8608","id":198203333,"number":8608,"title":"Register model before `postSave()`","user":{"login":"richardhj","id":1284725,"avatar_url":"https://avatars.githubusercontent.com/u/1284725?v=3","gravatar_id":"","url":"https://api.github.com/users/richardhj","html_url":"https://github.com/richardhj","followers_url":"https://api.github.com/users/richardhj/followers","following_url":"https://api.github.com/users/richardhj/following{/other_user}","gists_url":"https://api.github.com/users/richardhj/gists{/gist_id}","starred_url":"https://api.github.com/users/richardhj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardhj/subscriptions","organizations_url":"https://api.github.com/users/richardhj/orgs","repos_url":"https://api.github.com/users/richardhj/repos","events_url":"https://api.github.com/users/richardhj/events{/privacy}","received_events_url":"https://api.github.com/users/richardhj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-30T22:55:20Z","updated_at":"2016-12-30T22:55:20Z","closed_at":null,"body":"Please have a look at https://github.com/contao/core/blob/3.5.21/system/modules/core/library/Contao/Model.php#L516\r\n\r\nIs there a reason, you register the model `postSave()`? Wouldn't it be better to call the `postSave()` after the model was registered - even semantically?\r\nUnfortunately, this behavior leads to errors in my environment.\r\n## Details:\r\nI use the postSave to trigger an event\r\n```php\r\nclass Attendance extends Model\r\n{\r\n/**\r\n     * Trigger the SaveAttendanceEvent\r\n     *\r\n     * @param int $intType\r\n     */\r\n    protected function postSave($intType)\r\n    {\r\n        global $container;\r\n\r\n        parent::postSave($intType);\r\n\r\n        /** @var EventDispatcher $dispatcher */\r\n        $dispatcher = $container['event-dispatcher'];\r\n        $dispatcher->dispatch(SaveAttendanceEvent::NAME, new SaveAttendanceEvent($this, $this->cloneOriginal()));\r\n    }\r\n}\r\n``` \r\nA listener, which performs a `save()` on the model - which is not registered yet - leads into following error: \r\n```\r\nQuery error: Duplicate entry '9' for key 'PRIMARY' (INSERT INTO tl_mymodule (id, tstamp, offer, participant, status, sorting, created) VALUES ('9', '1483138351', '1', '1', '1', '0', '1483138351'))\r\n```"}}
{"actor":{"display_login":"richardhj"}}