Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Commit b455f42

Browse files
committed
This fixes lighthouse#1475, results incorrectly marked as immutable
Model#load checks the validity of the fields in the PK when determining if the object returned should be live or immutable. Unfortunately, it checks the raw values rather than the loaded values, resulting in data incorrectly marked as immutable if the PK countains fields (Enum, Flag, etc.) that are stored in a different format than the format in which they are represented within the application. This fixes the bug by loading the values that make up the PK before checking their validity. For a description of the symptoms, see the thread linked to from: http://datamapper.lighthouseapp.com/projects/20609/tickets/1475-strange-immutable-error
1 parent 524637c commit b455f42

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

lib/dm-core/model.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,8 @@ def load(records, query)
588588
model = discriminator && discriminator.load(record[discriminator]) || self
589589
model_key = model.key(repository_name)
590590

591-
resource = if model_key.valid?(key_values = record.values_at(*model_key))
591+
key_values = model_key.zip(record.values_at(*model_key)).map { |k,v| k.load(v) }
592+
resource = if model_key.valid?(key_values)
592593
identity_map = repository.identity_map(model)
593594
identity_map[key_values]
594595
end

0 commit comments

Comments
 (0)