假设我有:
var resourceful = require("resourceful");
BaseTopic = function () {
this.string("name");
this.string("slug");
}
slugify = function (someString) {
// do some things here
}
Topic = resourceful.define("topic", BaseTopic);
现在,我想要的是每次我保存Topic
的新实例时,slug字段都会更新,如下所示:
jsTopic = new Topic({name : "javascript"});
jsTopic.save(function (err, result) {
// in here slug field is defined
// so the slug field is saved to the db
console.log(result);
})
每次我创建一个新实例或保存它时,slug字段会自动填充。这可能吗?