batmanjs/batman — pull request #866 by rmosolgo (2013-10-23 17:57:17+00:00)
Title: Use the primaryKey's encoder.decode when decoding a hasMany child

If a model's `id` attribute is a string, but looks like an integer, it is [coerced to an integer] (https://github.com/batmanjs/batman/blob/master/src/model/model.coffee#L295) by Batman.Model. However, when a hasMany is loaded, its [raw JSON value](https://github.com/batmanjs/batman/blob/master/src/model/associations/has_many_association.coffee#L51) (a string in this case) is used to find if it was already loaded. This causes a double-load, because all the ids on the client have been converted to integers already -- the string doesn't find a match!

I added a [test case with integer-like string ids](), which failed until I [fetched and used encoder.decode]() when decoding a hasMany.

A couple outstanding questions:
- I used `relatedModel.prototype` to get to `_batman.get("encoders")` (which I just stole from [Model#toJSON](https://github.com/batmanjs/batman/blob/master/src/model/model.coffee#L323)) -- is there a better way to get there?
- This is my first go at QUnit. Could I have included that new model more gracefully? Is the test ok?