Skip to content

Commit

Permalink
Merge pull request #216 from andrykonchin/fix-index-detection-in-where
Browse files Browse the repository at this point in the history
Fix global index detection
  • Loading branch information
pboling authored Jan 6, 2018
2 parents 125951a + 5b45d6e commit fb9db64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dynamoid/criteria/chain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def key_present?
# But only do so if projects ALL attributes otherwise we won't
# get back full data
source.global_secondary_indexes.each do |_, gsi|
next unless query_keys.include?(gsi.hash_key.to_s) && gsi.projected_attributes == :all
next unless query.keys.map(&:to_s).include?(gsi.hash_key.to_s) && gsi.projected_attributes == :all
@hash_key = gsi.hash_key
@range_key = gsi.range_key
@index_name = gsi.name
Expand Down
9 changes: 9 additions & 0 deletions spec/dynamoid/criteria/chain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,15 @@ def request_params
expect(chain).to receive(:records_via_query).and_call_original
expect(chain.where(city: 'San Francisco').start(@customer2).all).to contain_exactly(@customer3)
end

it "does not use index if a condition for index hash key is other than 'equal'" do
chain = Dynamoid::Criteria::Chain.new(model)
expect(chain).to receive(:records_via_scan).and_call_original
expect(chain.where('city.begins_with' => 'San').count).to eq(3)
expect(chain.hash_key).to be_nil
expect(chain.range_key).to be_nil
expect(chain.index_name).to be_nil
end
end

it 'supports query on global secondary index with correct start key without table range key' do
Expand Down

0 comments on commit fb9db64

Please sign in to comment.