Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions supermodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,17 @@
toJSON: function() {
var o = Backbone.Model.prototype.toJSON.apply(this, arguments);
delete o[this.cidAttribute];
// if options set to include related models, set related model's toJSON response to
// the attribute of object the same value
if(this.withJSON) {
for (var i = 0; i < this.withJSON.length; i++) {
var related = this.withJSON[i];
// validate type of relationship exits and this model has an existing relationship
if (this[ related ] && this[ related ]() ) {
o[ related ] = this[ related ]().toJSON();
}
}
}
return o;
},

Expand Down