Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhruvaray/6929867 to your computer and use it in GitHub Desktop.
Save dhruvaray/6929867 to your computer and use it in GitHub Desktop.
Specify circular associations in an AMD context like require.js
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;
})
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;
})
@dhruvaray
Copy link
Author

Thanks - @mattcroberts

@azaslavsky
Copy link

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