Skip to content

Instantly share code, notes, and snippets.

@diorahman
Created November 20, 2012 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diorahman/4116327 to your computer and use it in GitHub Desktop.
Save diorahman/4116327 to your computer and use it in GitHub Desktop.
resourceful
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