title: Backbone-relational submodels with RequireJS
body: <p>I'm trying to find a way to use Backbone-relational submodels with RequireJS, where the submodels are in different files than the supermodel.</p>
  
  <p>For example:</p>
  
  <pre class="lang-js prettyprint-override"><code>// app.js
  define(function() {
    var app = {};
    var app.ns = {};
    Backbone.Relational.store.addModelScope(app.ns);
  });
  
  // Classroom/Person.js
  define(["app", "./Student", "./Professor"], function(app) {
    app.ns.Classroom.Person = Backbone.RelationalModel.extend({
      subModelTypes: {
        'Student': 'Classroom.Student'
        'Professor': 'Classroom.Professor'
      },
  
      alertHello: function() {}
    });
  
    return app.ns.Classroom.Person;
  });
  
  // Classroom/Student.js
  define(["require", "app", "./Person"], function(require, app) {
    app.ns.Classroom.Student = require("./Person").extend({
      alertHello: function() {
        alert("Hello, I am student " + this.get("name"));
      }
    });
  
    return app.ns.Classroom.Student;
  });
  
  // Classroom/PersonCollection.js
  define(["app", "./Person"], function (app, Person) {
    app.ns.Classroom.PersonCollection = Backbone.Collection.extend({
      model: Person
    });
  });
  
  // alertPeople.js
  define(["Classroom/PersonCollection"], function(PersonCollection) {
    var people = PersonCollection([{"name": "Bob", "type": "Person"}]);
    people.each(function(person) {
      person.alertHello();
    });
  });
  </code></pre>
  
  <p>When I execute alertPeople.js, I expect an alert of "Hello, I am student Bob", but instead I get this error: <code>Uncaught Error: Module name "Classroom/Person" has not been loaded yet for context: _</code> due to my circular dependency. What's a possible solution getting around this?</p>
  
  <p>My next issue may potentially be with the scope of of Backbone-relational. In my app.js file I add app.ns part of the of scope, and I make sure all of my models are defined in the app.ns object. I do this so when I define my subModelTypes, it can actually reference the submodels, but I'm not sure if this will work yet, as I cannot get past the circular dependency issue.</p>
  
  <p>Any help is greatly appreciated. Thank you!</p>