Skip to content

Instantly share code, notes, and snippets.

@kaworu
Last active August 29, 2015 13:57
Show Gist options
  • Save kaworu/9835562 to your computer and use it in GitHub Desktop.
Save kaworu/9835562 to your computer and use it in GitHub Desktop.
var util = require("util");
var Factory = require("rosie").Factory;
Factory.define('child')
.sequence('id')
Factory.define('parent')
.sequence('id')
.attr('children', function () {
return [
Factory.attributes('child', {parent_id: this.id()}),
Factory.attributes('child', {parent_id: this.id()}),
Factory.attributes('child', {parent_id: this.id()}),
];
})
console.log(util.inspect(Factory.build('parent', {id: 42})));
@kaworu
Copy link
Author

kaworu commented Mar 28, 2014

{ id: 42,
  children: 
   [ { parent_id: 1, id: 1 },
     { parent_id: 2, id: 2 },
     { parent_id: 3, id: 3 } ] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment