Skip to content

Commit 9153075

Browse files
committed
_.extend options and pass along in toJSON
1 parent b0d7a7d commit 9153075

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

backbone.JJRelational.coffee

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ do () ->
607607
toJSON: (options) ->
608608
options = options || {}
609609
# if options.withRelIDs, return the model with its related models represented only by ids
610-
if options.withRelIDs then return @.toJSONWithRelIDs()
610+
if options.withRelIDs then return @.toJSONWithRelIDs(options)
611611

612612
json = _.clone @.attributes
613613
# if options.bypass, return normal Backbone toJSON-function
@@ -626,23 +626,23 @@ do () ->
626626
if relValue
627627
if (relValue instanceof relation.relatedModel is true)
628628
if include.length is 0
629-
json[relation.key] = relValue.toJSONWithRelIDs()
629+
json[relation.key] = relValue.toJSONWithRelIDs(options)
630630
else if include.length is 1
631631
json[relation.key] = relValue.get(include[0])
632632
else
633-
json[relation.key] = relValue.toJSON {isSave: true, scaffold:include}
633+
json[relation.key] = relValue.toJSON(_.extend({}, options, {isSave: true, scaffold:include}))
634634
else
635635
# only id is present. check if 'id' is specified in includeInJSON
636636
json[relation.key] = if ( _.indexOf(include, relation.relatedModel.prototype.idAttribute) >=0 ) then relValue else null
637637
else
638638
json[relation.key] = null
639639
else if isManyType relation
640640
if include.length is 0
641-
json[relation.key] = relValue.toJSON {withRelIDs: true}
641+
json[relation.key] = relValue.toJSON(_.extend({}, options, {withRelIDs: true}))
642642
else if include.length is 1
643643
json[relation.key] = relValue.getArrayForAttribute include[0]
644644
else
645-
json[relation.key] = relValue.toJSON {isSave: true, scaffold:include}
645+
json[relation.key] = relValue.toJSON(_.extend({}, options, {isSave: true, scaffold:include}))
646646
if _.indexOf(include, 'id') >= 0 then json[relation.key].push relValue._relational.idQueue
647647

648648
# e.g. for views
@@ -651,9 +651,9 @@ do () ->
651651
for relation in @.relations
652652
relValue = @.get relation.key
653653
if isOneType relation
654-
json[relation.key] = if (relValue instanceof relation.relatedModel is true) then relValue.toJSONWithRelIDs() else relValue
654+
json[relation.key] = if (relValue instanceof relation.relatedModel is true) then relValue.toJSONWithRelIDs(options) else relValue
655655
else if isManyType relation
656-
json[relation.key] = relValue.toJSON {withRelIDs: true}
656+
json[relation.key] = relValue.toJSON(_.extend({}, options, {withRelIDs: true}))
657657

658658
if options.scaffold
659659
json = _.pick.apply that, [json, options.scaffold]

backbone.JJRelational.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backbone.JJRelational.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)