Dynamoid
Dynamoid copied to clipboard
find does not support range keys
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)