title: Backbone.js error: A 'url' property or function must be specified
body: <p>This is actually an answer not a question. Using backbone.js heavily. Hit a nasty little critter but did not find an explanation of my particular case online. Hopefully this will save someone else some time.</p>
  
  <p><strong>Symptom</strong></p>
  
  <p>Calling fetch() on a model pulled from a collection results in backbone error: "A 'url' property or function must be specified", even though both collection and model override sync().</p>
  
  <p><strong>Recreation</strong></p>
  
  <pre><code>AppPax.People = Backbone.Collection.extend({
      ...
      model: AppPax.Person,
      ...
  });
  
  ...
  AppPax.Person = AppPax.Model.extend({
      ...
      sync: function(method, model, options) {
  
          var response;
  
          switch (method) {
              case "read":    response = AppPax.getPerson(this.get("party_id"));
                              break;
          ...
      },
      ...
  });
  
  var c = new AppPax.People();
  c.fetch();
  var person = c.find(function(person){
      return(person.get("party_id") == "5");
  });
  // everything seemingly successful up to here (but not really)
  person.fetch();
  </code></pre>
  
  <p>Resulting backbone error: "A 'url' property or function must be specified"</p>
  
  <p><strong>Misdirected Investigation</strong></p>
  
  <p>So after some debugging and investigation, including looking at the backbone.js code it was clear that Backbone was looking for the url property on the Person model and couldn't find it. However, my Person model overrides sync() and when a model overrides sync() Backbone doesn't demand that the model supply a url property/method.</p>
  
  <p>I also noticed an anomaly: the models in the collection were never instantiated.</p>
  
  <p>All my other stuff based on the exact same pattern had been working fine for a long time.</p>
  
  <p>What to do?</p>
  
  <p><strong>Root Cause</strong></p>
  
  <p>The root cause turned out to be that in my module definition (AppPax) I had put the definition of Person after the definition of People (due to my now-not-so-useful habit of ordering code alphabetically).</p>
  
  <p>When Backbone made an instance of People at my request, it apparently didn't know about AppPax.Person so it created its own version of Person based on the model properties returned by c.fetch() -- without all my good stuff in it, including my sync() method.</p>
  
  <p>So when I tried to do person.fetch() it was using it's own, minimalist Person definition not mine, and that definition had no sync() method, so it looked for a url property/method on Person, didn't find it...choked.</p>
  
  <p>So I defined AppPax.Person before AppPax.People and all worked fine.</p>