As a programmer that wants to declare a referenced document with stork
I want an instance to save the reference if it has updates before saving itself
So that the instance manages the relationship between itself and the referenced document
var stork = require('stork')
, db = 'http://localhost:5984/stork_test'
, Person = stork.deliver('person', function() {
this.string('firstName');
this.string('lastName');
})
, Discussion = stork.deliver('discussion', function() {
this.ref('author', Person, { required: true })
})
, person = Person.new({ firstName: 'Charles', lastName: 'Darwin' })
, discussion = Discussion.new({author: person})
;
discussion.to(db).save(function(err, user) {
if(err) {
return console.log('failed to save discussion', err);
}
// Since this succeeded, we should now have one
// Person document in the database. The Discussion
// document should have a property named $authorId
// that contains the id of the newly saved
// Person document.
console.log('discussion saved successfully');
});
As a programmer that wants to declare a referenced document with stork
I want an instance to save the reference if it has updates before saving itself
So that the instance manages the relationship between itself and the referenced document