{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/10107","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/10107/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/10107/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/10107/events","html_url":"https://github.com/yiisoft/yii2/issues/10107","id":115437310,"number":10107,"title":"Refresh model in yii\\rest\\CreateAction ?","user":{"login":"karpy47","id":8948719,"avatar_url":"https://avatars.githubusercontent.com/u/8948719?v=3","gravatar_id":"","url":"https://api.github.com/users/karpy47","html_url":"https://github.com/karpy47","followers_url":"https://api.github.com/users/karpy47/followers","following_url":"https://api.github.com/users/karpy47/following{/other_user}","gists_url":"https://api.github.com/users/karpy47/gists{/gist_id}","starred_url":"https://api.github.com/users/karpy47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karpy47/subscriptions","organizations_url":"https://api.github.com/users/karpy47/orgs","repos_url":"https://api.github.com/users/karpy47/repos","events_url":"https://api.github.com/users/karpy47/events{/privacy}","received_events_url":"https://api.github.com/users/karpy47/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-06T05:40:55Z","updated_at":"2015-11-06T05:52:42Z","closed_at":"2015-11-06T05:52:42Z","body":"I have a model where I use TimestampBehavior like this:\r\n\r\n    [\r\n\t'class' => TimestampBehavior::className(),\r\n        'value' => new Expression('NOW()'),\r\n    ]\r\n\r\nThis class is then extended from when creating a Rest API.\r\nNow, when creating a new object using the API's default yii\\rest\\CreateAction a new object is created, but when returning the newly created object to the view-action all date-time attributes related to TimeStampBehaviour still show the unevaluated value: \"object Expression('NOW()')\".\r\n\r\nIf I insert \"$model->refresh\" after \"$model->save()\" in the run-action of yii\\rest\\CreateAction it works as expected, but that is obviously not the way to solve it. \r\nGuess I could make another CreateAction or point to another ViewAction using the CreateAction->$viewAction parameter. \r\nOr is this something that could be improved in yii\\rest\\CreateAction ?"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/154306352","html_url":"https://github.com/yiisoft/yii2/issues/10107#issuecomment-154306352","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/10107","id":154306352,"user":{"login":"karpy47","id":8948719,"avatar_url":"https://avatars.githubusercontent.com/u/8948719?v=3","gravatar_id":"","url":"https://api.github.com/users/karpy47","html_url":"https://github.com/karpy47","followers_url":"https://api.github.com/users/karpy47/followers","following_url":"https://api.github.com/users/karpy47/following{/other_user}","gists_url":"https://api.github.com/users/karpy47/gists{/gist_id}","starred_url":"https://api.github.com/users/karpy47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karpy47/subscriptions","organizations_url":"https://api.github.com/users/karpy47/orgs","repos_url":"https://api.github.com/users/karpy47/repos","events_url":"https://api.github.com/users/karpy47/events{/privacy}","received_events_url":"https://api.github.com/users/karpy47/received_events","type":"User","site_admin":false},"created_at":"2015-11-06T05:52:42Z","updated_at":"2015-11-06T05:52:42Z","body":"Solved it by adding this to my API-model...\r\n\r\n    public function afterSave($insert, $changedAttributes) {\r\n        $this->refresh();\r\n    }\r\n\r\nSeemed like the easiest solution."}}