-
-
Save tgriesser/9822343 to your computer and use it in GitHub Desktop.
Revisions
-
tgriesser revised this gist
Mar 28, 2014 . 1 changed file with 7 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,18 +13,13 @@ var Child = Bookshelf.Model.extend({ } }); Parent.forge({name: "Parent"}).save() .then(function (parent) { // or parent.child().save({name: 'Child'}) // using .related just throws it on the // parent's .relations hash return parent.related('child').save({name: 'Child'}); }) .then(function (child) { res.send(child); }); -
stefanhenze created this gist
Mar 27, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ var Parent = Bookshelf.Model.extend({ tableName: 'parent', child: function() { return this.hasOne(Child); } }); var Child = Bookshelf.Model.extend({ tableName: 'child', //this has an attribute parent_id parent: function() { return this.belongsTo(Parent); } }); var parent, child; Parent.forge({name: "Parent"}).save() .then(function (_parent) { parent = _parent; return Child.forge({name: "Child"}).save(); }) .then(function (_child) { child = _child; child.related('parent').set(parent); return child.save(); }) .then(function(saved) { res.send(saved); });