sequelize/sequelize — pull request #863 by lemon-tree (2013-08-29 12:44:43+00:00)
Title: Support for eager loading with non-'id' primary keys + extras

This fixes #847 where eager loading could not be performed when a non-'id' primary key was in use due to hard coded 'id' assumption in the joins. This follows what appears to be the Sequelize convention (from throughout current code), whereby only single custom primary keys are supported on each table. Tests for the new code are also in place.

Also addressed in this PR as a side affect of fixing eager loading:

- Junction tables and join columns now have the correct type based upon the target table's primary key type. Before it would default to integer, even if the target table's primary key was of a different type. This led to casting errors between the two types which could have led to the wrong rows being returned on a join.

- Association setters and adders for many-many joins were using the wrong columns when a non-'id' primary key was in use, leading to associations not being created or destroyed correctly.

Note: There are probably a few other issue that this might close and could be reviewed. These are #655, #852, #694, #143, #818, #139. I have tested the code in some of those issues and a number of them appear resolved (#252, #655, #818), but it'd probably be better for for the original people to check with their own code (if they're still around). There may also be others, but I don't have all day to search for them. Also, some of those are already closed, but without workarounds or an incomplete solution.