Closed toddself closed 10 years ago
Example:
var Backbone = require('backbone'); var mongoSync = require('backbone-mongo').sync; var Inner = Backbone.Model.extend({ urlRoot: 'mongodb://localhost:27017/inner' }); Inner.prototype.sync = mongoSync(Inner); var Outer = Backbone.Model.extend({ urlRoot: 'mongodb://localhost:27017/outer', schema: { inner: function(){ return ['hasOne', Inner]; } } }); Outer.prototype.sync = mongoSync(Outer); var outer = new Outer(); outer.set({foo: 'bar', inner: new Inner({fie: 'baz'})}); { cid: 'c5', attributes: { howdy: 'ho', inner: { cid: 'c10', attributes: [Object], _changing: false, _previousAttributes: {}, changed: {}, _pending: false, _orm: [Object] } }, changed: { inner: { cid: 'c10', attributes: [Object], _changing: false, _previousAttributes: {}, changed: {}, _pending: false, _orm: [Object] } }, _orm: { needs_load: {}, is_initialized: true, rel_dirty: { inner: true } }, _changing: false, _previousAttributes: { howdy: 'ho' }, _pending: false } outer.get('inner'); { cid: 'c10', attributes: { fie: 'baz' }, _changing: false, _previousAttributes: {}, changed: {}, _pending: false, _orm: { needs_load: {}, is_initialized: true } } outer.toJSON(); {foo: 'bar'}
Expected:
outer.toJSON(); { foo: 'bar', inner: { fie: 'baz' } }
Wait. There's no way this could work. oops!
Example:
Expected: