Skip to content

Instance referring to other documents calls save on referenced docs, if needed, and saves self #24

Description

@realistschuckle

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');
}); 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions