composite-primary-keys/composite_primary_keys — pull request #207 by pareeohnos (2014-05-29 15:08:59+00:00)
Title: Fixed issue where 'id_was' would be an array with an array, not an array...

Fixes an issue with the `attribute_was` override. When attempting to update a record, rails calls the `id_was` method. This override resulted in an incorrect value for this, resulting in an invalid query. As an example, with an instance of a model with the foreign keys `[:field_a, :id]`, calling `id_was` results in the array

['value in field a', ['value in field a', 1]]

The contained array is an instance of the Composite primary key class. This nesting of array causes rails to incorrectly generate a query such as

UPDATE "models" SET "field_b" = "value in field b" WHERE("models"."field_a" = "value in field a" AND "models"."id" = "value in field a", 1)

This PR solves the issue, by fetching the requested attribute value from the `ids_hash` method instead of simply requesting it directly from the model. In the case where `id` is still used as a primary key, calling `id` on the model returns the composite primary key, not the original `id` value