3

假设我有:

var resourceful = require("resourceful");

BaseTopic = function () {
    this.string("name");
    this.string("slug");
}

slugify = function (someString) {
    // do some things here
}

Topic = resourceful.define("topic", BaseTopic);

现在,我想要的是每次保存Topicslug 字段的新实例时都会更新,如下所示:

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 字段都会自动填充。那可能吗 ?

4

0 回答 0