Dynamoid icon indicating copy to clipboard operation
Dynamoid copied to clipboard

find does not support range keys

Open luxx opened this issue 12 years ago • 0 comments

You have to use find_all instead of find for tables with range keys because in dynamoid find destructively calls flatten and unique on the array of ids. Why is this a problem? Because find calls find_all, which calls read, which eventually calls AWS::DynamoDB::BatchGet, which expects arguments in this form:

ids = [ ['hash_key1', 'range_key1'], ['hash_key2', 'range_key2'] ]

flattened becomes

ids.flatten.uniq
=> ["hash_key1", "range_key1", "hash_key2", "range_key2"]

which is wrong and fails. The solution is to change Dynamoid\lib\dynamoid\finders.rb#26 to only flatten the ids when the table has no range key, for example:

  ids = Array(self.range_key ? ids.flatten.uniq : ids.uniq)

luxx avatar Jan 23 '13 20:01 luxx