toranb/ember-data-django-rest-adapter — pull request #22 by craigteegarden (2013-06-11 18:33:07+00:00)
Title: failing test showing incorrect URL is requested when a model contains mu...

...ltiple nested attributes of the same model type.

The issue is that the [`buildFindManyUrlWithParent()`](https://github.com/toranb/ember-data-django-rest-adapter/blob/master/packages/ember-data-django-rest-adapter/lib/adapter.js#L78) method iterates through all relationships of a model and only matches the attribute's type. If there are multiple nested attributes of the same type then the last attribute of that type that is encountered by the loop will always be used, no matter which attribute was requested.

From the failing test:

Animal = DS.Model.extend({
name: DS.attr('string')
});

Animal.toString = function() {
return "App.Animal";
};

Herd = DS.Model.extend({
name: DS.attr('string'),
members: DS.hasMany(Animal),
outcasts: DS.hasMany(Animal)
});

Herd.toString = function() {
return "App.Herd";
};

The same URL will be requested for both of these calls:

herd = App.Herd.find(1);
herd.get('members'); // URL will be "/herd/1/outcasts"
herd.get('outcasts'); // URL will be "/herd/1/outcasts"

I'm not exactly sure the best way to resolve this. It didn't appear that there was an easy way to figure out the attribute's name that causes `buildFindManyUrlWithParent()` to be called... I hope someone else can point me in the right direction.