{"action":"created","issue":{"url":"https://api.github.com/repos/Starcounter/Starcounter/issues/2767","labels_url":"https://api.github.com/repos/Starcounter/Starcounter/issues/2767/labels{/name}","comments_url":"https://api.github.com/repos/Starcounter/Starcounter/issues/2767/comments","events_url":"https://api.github.com/repos/Starcounter/Starcounter/issues/2767/events","html_url":"https://github.com/Starcounter/Starcounter/issues/2767","id":87247728,"number":2767,"title":"Hook<T>.OnDelete behaviour","user":{"login":"miyconst","id":6435556,"avatar_url":"https://avatars.githubusercontent.com/u/6435556?v=3","gravatar_id":"","url":"https://api.github.com/users/miyconst","html_url":"https://github.com/miyconst","followers_url":"https://api.github.com/users/miyconst/followers","following_url":"https://api.github.com/users/miyconst/following{/other_user}","gists_url":"https://api.github.com/users/miyconst/gists{/gist_id}","starred_url":"https://api.github.com/users/miyconst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miyconst/subscriptions","organizations_url":"https://api.github.com/users/miyconst/orgs","repos_url":"https://api.github.com/users/miyconst/repos","events_url":"https://api.github.com/users/miyconst/events{/privacy}","received_events_url":"https://api.github.com/users/miyconst/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Starcounter/Starcounter/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/Starcounter/Starcounter/labels/question","name":"question","color":"02d7e1"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-06-11T07:43:39Z","updated_at":"2015-06-12T07:05:15Z","closed_at":null,"body":"This is a subissue of https://github.com/Starcounter/Starcounter/issues/2760"},"comment":{"url":"https://api.github.com/repos/Starcounter/Starcounter/issues/comments/111386897","html_url":"https://github.com/Starcounter/Starcounter/issues/2767#issuecomment-111386897","issue_url":"https://api.github.com/repos/Starcounter/Starcounter/issues/2767","id":111386897,"user":{"login":"per-samuelsson","id":2902045,"avatar_url":"https://avatars.githubusercontent.com/u/2902045?v=3","gravatar_id":"","url":"https://api.github.com/users/per-samuelsson","html_url":"https://github.com/per-samuelsson","followers_url":"https://api.github.com/users/per-samuelsson/followers","following_url":"https://api.github.com/users/per-samuelsson/following{/other_user}","gists_url":"https://api.github.com/users/per-samuelsson/gists{/gist_id}","starred_url":"https://api.github.com/users/per-samuelsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/per-samuelsson/subscriptions","organizations_url":"https://api.github.com/users/per-samuelsson/orgs","repos_url":"https://api.github.com/users/per-samuelsson/repos","events_url":"https://api.github.com/users/per-samuelsson/events{/privacy}","received_events_url":"https://api.github.com/users/per-samuelsson/received_events","type":"User","site_admin":false},"created_at":"2015-06-12T07:05:15Z","updated_at":"2015-06-12T07:05:15Z","body":"> I know, it sounds too complicated, but I could not think up a better way with current limitations.\r\n\r\nI'm probably missing something from your description, but I can't see what would not work for the same use case, if we had changed to what I proposed here:\r\n\r\n> As you wrote somewhere in #2760, its a problem also that only defining classes have access to the OnDelete callback, and that its part of an interface. Maybe we should turn that into a code-host global event, replacing the IEntity interface as a whole? In such case, not only the defining class can interpret deletes (of itself), but any class. This would solve at least some of the hazzle.\r\n\r\nWith such solution, we encourage decoupling too. Any piece of code can easily subscribe to events triggered when - or actually, *before* - any object of an arbitrary database class is deleted, and developers could quite easily couple that with commit hooks if required.\r\n\r\n```C#\r\nvoid Main() {\r\n  // New hook that complement/replace IEntity.OnDelete, allowing\r\n  // any arbitrary piece of code to subscribe to events triggering when\r\n  // a database class is deleted, but before the object is inaccessible\r\n  Hook<Image>.BeforeDelete += (image) => {\r\n    var photo = image as Photo;\r\n    if (photo != null) {\r\n      new DeletedPhoto(image.FilePath);\r\n    }\r\n  }\r\n  Hook<DeletedPhoto>.OnInsert(p => { p.DeleteFile(); });\r\n}\r\n```"}}