Relational method calls should be available on resource's constructor #110

Closed
Marak opened this Issue Aug 28, 2012 · 2 comments

Projects

None yet

3 participants

@Marak
Contributor
Marak commented Aug 28, 2012

It seems that the only way to call a relational method ( i.e., Resource.createChild, or Author.createArticle ), is on an instance of the parent resource.

Relational method calls should be available on both the constructor and the instance.

For example:

var resourceful = require('../lib/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 article "good-article", written by "bob"
//

This works

Author.create({ id: 'bob'}, function(err, bob){
  console.log(err, bob)
  bob.createArticle({ id: 'good-article'}, function(err, article){
    console.log(err, article)
  });
});

This does not

// console.log(Author.createArticle.toString())
Author.createArticle({
  id: 'bob',
  article_id: 'good-article'
}, function(err, bob){
  console.log(err, bob)
});

Both of these api's should work

Judging from the Relational Resources docs this is solved right?

@Marak Marak closed this May 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment