-
-
Save tgriesser/9822343 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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); | |
} | |
}); | |
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment