Skip to content

Commit c5bd97a

Browse files
committed
optimistically set reverse relationship keys when creating a model if relationsInstalled is true and the model's attributes do not already contain the key
1 parent 01569f1 commit c5bd97a

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

backbone.JJRelational.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ do () ->
718718
@.addToRelation val, rel, false
719719
else if _.isObject(val) and val instanceof Backbone.Model is false
720720
# is an object -> Model has to be created and populated -> then add
721+
val[rel.reverseKey] = @ if @.relationsInstalled and !val[rel.reverseKey]? # optimistically set the reverse relationship key if it doesn't already exist
721722
if rel.polymorphic and rel.collectionType
722723
newModel = new (Backbone.JJRelational.CollectionTypes[rel.collectionType].prototype.model)(val)
723724
else

backbone.JJRelational.js

Lines changed: 3 additions & 0 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)