@@ -607,7 +607,7 @@ do () ->
607
607
toJSON : (options ) ->
608
608
options = options || {}
609
609
# 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 )
611
611
612
612
json = _ .clone @ .attributes
613
613
# if options.bypass, return normal Backbone toJSON-function
@@ -626,23 +626,23 @@ do () ->
626
626
if relValue
627
627
if (relValue instanceof relation .relatedModel is true )
628
628
if include .length is 0
629
- json[relation .key ] = relValue .toJSONWithRelIDs ()
629
+ json[relation .key ] = relValue .toJSONWithRelIDs (options )
630
630
else if include .length is 1
631
631
json[relation .key ] = relValue .get (include[0 ])
632
632
else
633
- json[relation .key ] = relValue .toJSON {isSave : true , scaffold : include}
633
+ json[relation .key ] = relValue .toJSON ( _ . extend ({}, options, {isSave : true , scaffold : include}))
634
634
else
635
635
# only id is present. check if 'id' is specified in includeInJSON
636
636
json[relation .key ] = if ( _ .indexOf (include, relation .relatedModel .prototype .idAttribute ) >= 0 ) then relValue else null
637
637
else
638
638
json[relation .key ] = null
639
639
else if isManyType relation
640
640
if include .length is 0
641
- json[relation .key ] = relValue .toJSON {withRelIDs : true }
641
+ json[relation .key ] = relValue .toJSON ( _ . extend ({}, options, {withRelIDs : true }))
642
642
else if include .length is 1
643
643
json[relation .key ] = relValue .getArrayForAttribute include[0 ]
644
644
else
645
- json[relation .key ] = relValue .toJSON {isSave : true , scaffold : include}
645
+ json[relation .key ] = relValue .toJSON ( _ . extend ({}, options, {isSave : true , scaffold : include}))
646
646
if _ .indexOf (include, ' id' ) >= 0 then json[relation .key ].push relValue ._relational .idQueue
647
647
648
648
# e.g. for views
@@ -651,9 +651,9 @@ do () ->
651
651
for relation in @ .relations
652
652
relValue = @ .get relation .key
653
653
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
655
655
else if isManyType relation
656
- json[relation .key ] = relValue .toJSON {withRelIDs : true }
656
+ json[relation .key ] = relValue .toJSON ( _ . extend ({}, options, {withRelIDs : true }))
657
657
658
658
if options .scaffold
659
659
json = _ .pick .apply that, [json, options .scaffold ]
0 commit comments