Created
November 20, 2012 06:13
-
-
Save diorahman/4116327 to your computer and use it in GitHub Desktop.
resourceful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resourceful = require('resourceful'); | |
resourceful.use('memory'); | |
// | |
// First, create two resources: Author and Article | |
// | |
var Author = resourceful.define('author'); | |
Author.string('name'); | |
var Article = resourceful.define('article'); | |
Article.string('title'); | |
// | |
// Now we add a special property to Article indicating that Author is its parent | |
// | |
Article.parent('author'); | |
// | |
// Create a new author "bob" | |
// | |
Author.create({ | |
id: 'bob' | |
}, function(err, bob){ | |
// | |
// Create a new article for bob | |
// | |
bob.createArticle({ id: "cool-story", title: "A cool story by bob." }, function(err, result){ | |
// | |
// why we have empty array in here ? | |
// | |
console.log(bob.article_ids); | |
console.log(bob.article_ids.length); | |
// | |
// Get all of bob's articles | |
// | |
bob.articles(function(err, result){ | |
console.log(result); | |
}); | |
Article.get('author/bob/cool-story', function(err, result){ | |
console.log(result); | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment