PaulUithol/Backbone-relational — Issue #80: fetchRelated makes assumption that I don't think holds
Author: Aqueous
Created: 2012-02-22 16:34:05+00:00
State: open

I'm using a One-to-Many relation. My back-end is RequestTracker's REST interface (http://requesttracker.wikia.com/wiki/REST). My model and respective collection are called Ticket and HistoryItemCollection. Basically a HistoryItemCollection is the entire History for a given Ticket object.

In fetchRelated a comment says the following:

// An assumption is that when 'Backbone.Collection.url' is a function, it can handle building of set urls.
// To make sure it can, test if the url we got by supplying a list of models to fetch is different from
// the one supplied for the default fetch action (without args to 'url').

I guess I don't understand why this is a safe assumption. For instance, in my case, my REST backend (RequestTracker) only supports getting the entire collection at the same time. I cannot construct a single URL that gets a set of individual models. However, this doesn't bother me that much, since I can still get the entire History of a Ticket without having to fetch each individual item, and then disregard the items I don't need. So, essentially, the collection.url() for fetching the entire collection and the ur() for fetching a set, ought to be the same. However, Backbone-relational only uses the url when the set url is different from the collection url, and disregards the url altogether otherwise, opting instead- I think - to fetch the models one at a time.

This also creates problems when I am trying to fetch the collection manually, since my backbone-sync override passes no arguments to my collection.url(), even though I still want to fetch the entire collection.

Can you explain more why this should be assumed?