Forked from mattcroberts/reverseRelationTest_index.html
Last active
December 25, 2015 06:09
-
-
Save dhruvaray/6929867 to your computer and use it in GitHub Desktop.
Specify circular associations in an AMD context like require.js
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
define([ | |
"backbone.associations", | |
"Person" | |
], function(Associations, Person){ | |
var House = Backbone.AssociatedModel.extend({ | |
relations:[{ | |
key:"person", | |
type:Backbone.One, | |
relatedModel: function(){ return require("Person");} | |
}] | |
}); | |
return House; | |
}) |
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
define([ | |
"backbone.associations", | |
"House" | |
], function(Associations, House){ | |
var Person = Backbone.AssociatedModel.extend({ | |
relations:[{ | |
key:"house", | |
type:Backbone.One, | |
relatedModel: function(){ return require("House");} | |
}] | |
}); | |
return Person; | |
}) |
Quick question - why do we need to load the required module again in the relatedModel function? If instead we had
relatedModel: House,
wouldn't that still work as a closure?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks - @mattcroberts