{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/8230","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/8230/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/8230/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/8230/events","html_url":"https://github.com/yiisoft/yii2/issues/8230","id":72052589,"number":8230,"title":"Relations update and delete","user":{"login":"Alex-Bond","id":1134715,"avatar_url":"https://avatars.githubusercontent.com/u/1134715?v=3","gravatar_id":"","url":"https://api.github.com/users/Alex-Bond","html_url":"https://github.com/Alex-Bond","followers_url":"https://api.github.com/users/Alex-Bond/followers","following_url":"https://api.github.com/users/Alex-Bond/following{/other_user}","gists_url":"https://api.github.com/users/Alex-Bond/gists{/gist_id}","starred_url":"https://api.github.com/users/Alex-Bond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alex-Bond/subscriptions","organizations_url":"https://api.github.com/users/Alex-Bond/orgs","repos_url":"https://api.github.com/users/Alex-Bond/repos","events_url":"https://api.github.com/users/Alex-Bond/events{/privacy}","received_events_url":"https://api.github.com/users/Alex-Bond/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-04-30T03:38:21Z","updated_at":"2015-05-01T06:42:03Z","closed_at":"2015-04-30T08:26:52Z","body":"Hi!\r\n\r\nI found out that we don't any functionality to simplify cascade updating and deleting of models.\r\n\r\nFor example:\r\nI have product table `Products`.\r\nI have table with images for this product `ProductImages`.\r\n\r\nWhen i remove product i need to remove all associated images.\r\n\r\nGuys in Gitter offer me to use database level relations, but in this case images associates with `ProductImages` will not be removed because removing configured in `afterDelete()` method.\r\n\r\nIm offering to create something like this (part of `Products` model):\r\n```\r\n   public function getImages()\r\n    {\r\n        return $this->hasMany( ProductsImages::className(), [ 'product_id' => 'id' ] )->cascadeOnDelete();\r\n    }\r\n```\r\n\r\nWhat core developer think about this?"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/98058632","html_url":"https://github.com/yiisoft/yii2/issues/8230#issuecomment-98058632","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/8230","id":98058632,"user":{"login":"Alex-Bond","id":1134715,"avatar_url":"https://avatars.githubusercontent.com/u/1134715?v=3","gravatar_id":"","url":"https://api.github.com/users/Alex-Bond","html_url":"https://github.com/Alex-Bond","followers_url":"https://api.github.com/users/Alex-Bond/followers","following_url":"https://api.github.com/users/Alex-Bond/following{/other_user}","gists_url":"https://api.github.com/users/Alex-Bond/gists{/gist_id}","starred_url":"https://api.github.com/users/Alex-Bond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alex-Bond/subscriptions","organizations_url":"https://api.github.com/users/Alex-Bond/orgs","repos_url":"https://api.github.com/users/Alex-Bond/repos","events_url":"https://api.github.com/users/Alex-Bond/events{/privacy}","received_events_url":"https://api.github.com/users/Alex-Bond/received_events","type":"User","site_admin":false},"created_at":"2015-05-01T06:42:03Z","updated_at":"2015-05-01T06:42:03Z","body":"When i use DB relations YII will not call `afterDelete()`."}}