{"action":"reopened","issue":{"url":"https://api.github.com/repos/arangodb/arangodb/issues/1257","labels_url":"https://api.github.com/repos/arangodb/arangodb/issues/1257/labels{/name}","comments_url":"https://api.github.com/repos/arangodb/arangodb/issues/1257/comments","events_url":"https://api.github.com/repos/arangodb/arangodb/issues/1257/events","html_url":"https://github.com/arangodb/arangodb/issues/1257","id":59029140,"number":1257,"title":"Foxx Model lifecycle events","user":{"login":"pekeler","id":42363,"avatar_url":"https://avatars.githubusercontent.com/u/42363?v=3","gravatar_id":"","url":"https://api.github.com/users/pekeler","html_url":"https://github.com/pekeler","followers_url":"https://api.github.com/users/pekeler/followers","following_url":"https://api.github.com/users/pekeler/following{/other_user}","gists_url":"https://api.github.com/users/pekeler/gists{/gist_id}","starred_url":"https://api.github.com/users/pekeler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pekeler/subscriptions","organizations_url":"https://api.github.com/users/pekeler/orgs","repos_url":"https://api.github.com/users/pekeler/repos","events_url":"https://api.github.com/users/pekeler/events{/privacy}","received_events_url":"https://api.github.com/users/pekeler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-02-26T06:57:45Z","updated_at":"2015-05-06T16:56:58Z","closed_at":null,"body":"I’m trying to add an updatedAt field to my model and have a couple of questions.\r\n\r\n```\r\nFoxx.Model.extend({\r\n  schema: {\r\n    name: Joi.string().trim(),\r\n    updatedAtTimestamp: Joi.date()\r\n  },\r\n```\r\n\r\nI think the model should be responsible for setting updatedAtTimestamp. I tried overwriting the model’s `set` method, but it seems that the repository calls `set` too late for my purpose.\r\n\r\nNext, try it with a `beforeSave` hook. But where? The documentation for Backbone’s extend suggests to define an `initialize` function. However, initialize is never called. Is extend perhaps from an older version of Backbone? Would it make sense to upgrade to the latest version of extend for the next version of ArangoDB?\r\n\r\nAnyways, implementing a constructor for my model instead\r\n```\r\n  constructor: function() {\r\n    this.on('beforeUpdate', (data) => data.updatedAtTimestamp = Date.now());\r\n    Foxx.Model.apply(this, arguments);\r\n  }\r\n```\r\nNow isn’t it a bit weird to have the EventEmitter (my model) register itself as listener? I think it would be nicer if I could just implement a beforeSave method on my model and the repository would automatically call it if it exists.\r\n\r\nI also find it unintuitive that my beforeUpdate handler can’t use this.set and has to modify the passed-in data instead (and thereby bypassing schema validation).\r\n\r\nAnd then I noticed that several methods on Foxx.Repository are not emitting any of the lifecycle events:\r\n- updateById\r\n- replace\r\n- replacebyId\r\n\r\nI think all three methods should emit the same events as update does.\r\n"}}