3

Suppose i have :

var resourceful = require("resourceful");

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

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

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

Now, what i want is every time i save a new instance of Topic the slug field gets updated, like this :

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);
})

So the slug field is automatically filled, every time i make a new instance or saving it. Is that possible ?

Faris Nasution
  • 3,450
  • 5
  • 24
  • 29
  • Use https://github.com/Aaronontheweb/node-slugs. In the callback do something like result.slug = slugs(result.name);. That's all there is to it. – thgie Mar 28 '13 at 10:44

0 Answers0