Fixed a dependency on the order of association mappings
Cleaned up tests a bit
Take entity from context if keys match