{"action":"closed","issue":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/5316","labels_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/5316/labels{/name}","comments_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/5316/comments","events_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/5316/events","html_url":"https://github.com/orientechnologies/orientdb/issues/5316","id":116835210,"number":5316,"title":"Dynamic Hooks: Inheritance & Other Issues","user":{"login":"devspacenine","id":842594,"avatar_url":"https://avatars.githubusercontent.com/u/842594?v=3","gravatar_id":"","url":"https://api.github.com/users/devspacenine","html_url":"https://github.com/devspacenine","followers_url":"https://api.github.com/users/devspacenine/followers","following_url":"https://api.github.com/users/devspacenine/following{/other_user}","gists_url":"https://api.github.com/users/devspacenine/gists{/gist_id}","starred_url":"https://api.github.com/users/devspacenine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devspacenine/subscriptions","organizations_url":"https://api.github.com/users/devspacenine/orgs","repos_url":"https://api.github.com/users/devspacenine/repos","events_url":"https://api.github.com/users/devspacenine/events{/privacy}","received_events_url":"https://api.github.com/users/devspacenine/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-13T19:24:11Z","updated_at":"2015-11-13T19:35:21Z","closed_at":"2015-11-13T19:35:21Z","body":"I think this is a mix of an issue and a feature request for 2.2. I'm still learning about how OrientDB works, so hopefully I'm just missing something in the documentation.\r\n\r\nI have an abstract class, `BaseVertex`, that extends `V` and `OTriggered`, with 2 columns: `_created`, `_modified`.\r\n\r\n```sql\r\nCREATE CLASS BaseVertex Extends V, OTriggered ABSTRACT;\r\n\r\nCREATE PROPERTY BaseVertex._created DATETIME;\r\n\r\nCREATE PROPERTY BaseVertex._modified DATETIME;\r\n```\r\n\r\nI then create dynamic hooks for `onAfterCreate` and `onAfterUpdate` to change the values of the `_created` and `_modified` field.\r\n\r\n```sql\r\nCREATE FUNCTION updateCreated \"doc.field('_created', new Date().getTime()); doc.save(); return;\" LANGUAGE Javascript;\r\n\r\nCREATE FUNCTION updateModified \"doc.field('_modified', new Date().getTime()); doc.save().return;\" LANGUAGE Javascript;\r\n\r\nALTER CLASS BaseVertex CUSTOM onAfterCreate=updateCreated;\r\n\r\nALTER CLASS BaseVertex CUSTOM onAfterUpdate=updateModified;\r\n```\r\n\r\nI did not include an initial `_modified` value in the `onAfterCreate` hook because OrientDB seems to call `onAfterCreate` **and** `onAfterUpdate` hooks when you create a document (is that a bug or is that intended? not sure...)\r\n\r\nNext, I create a class, `Company`, that extends 'BaseVertex' and create a dynamic hook to alter some field after update.\r\n\r\n```sql\r\nCREATE CLASS Company EXTENDS BaseVertex;\r\n\r\nCREATE FUNCTION testUpdate \"doc.field('test', 'test'); doc.save(); return;\" LANGUAGE Javascript;\r\n\r\nALTER CLASS Company CUSTOM onAfterUpdate=testUpdate;\r\n```\r\n\r\nFinally, I create a 'Company' vertex then update an arbitrary field a few seconds later.\r\n\r\n```sql\r\nCREATE VERTEX Company;\r\n\r\n/* wait a few seconds */\r\nUPDATE <someRID> SET name = 'Test Company';\r\n```\r\n\r\n**What I expect to happen**: A `Company` vertex is initially created with `_created` and `_modified` set to similar values (...would be exactly equal if only onAfterCreate was called and I set `_modified` in that hook function). After updating the `Company` document, the `name` field is set to \"Test Company\", the `test` field is set to \"test\", and the `_modified` field is now a few seconds later than the `_create` field.\r\n\r\n**What actually happens**: A `Company` vertex is initially create with `_created` and `_modified` set to similar values. After updating the `Company` document, the `name` field is set to \"Test Company\", the `test` field is set to \"test\", and the `_modified` field is unchanged.\r\n\r\nIt seems that the abstract class' *onAfterCreate* and *onAfterUpdate* hooks are both called when you create a document of some type that extends it (though, the child class' *onAfterUpdate* hook is not called, which is strange...). However, after updating the document of a child class, only the child document's hooks are called."}}