PaulUithol/Backbone-relational — pull request #198 by kopatsy (2012-09-23 07:25:46+00:00)
Title: Call parse before retrieving idAttribute

I have an API that returns the object payload as follow:
{
result : {
id : 123
field1 : ...
}
}

I have a custom parse method on my models that essentially does 'return response.result'.

In the findOrCreate method, the idAttribute must be retrieved and
it uses item[ type.prototype.idAttribute ]. This is fine when the
API returns the id as a top level key but it brakes otherwise and
parse must be called first.

I have not had a chance to write a unit test yet. I am new to javascript and backbone and I wanted to get your feedback on the change before I invest more time implementing a test case. This fix solves my particular problem but it may have side effects I am not aware of. Without this fix, I would get 'Cannot instantiate more than one Backbone.RelationalModel with the same id per type! ' errors since findOrCreate would never be able to pull the model idAttribute.