Skip to content

Commit

Permalink
include key in where clause when no matching field
Browse files Browse the repository at this point in the history
  • Loading branch information
rferg committed Jan 9, 2024
1 parent 8796078 commit fa321b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/active_force/active_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def raise_if_bind_arity_mismatch(expected_var_count, actual_var_count)

def build_conditions_from_hash(hash)
hash.map do |key, value|
applicable_predicate mappings[key], value
field = mappings.fetch(key, key&.to_s)
applicable_predicate(field, value)
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/active_force/active_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@
end
end
end

context 'when given attributes Hash with fields that do not exist on the SObject' do
it 'uses the given key in an eq condition' do
expected = 'SELECT Id FROM table_name WHERE (no_attribute = 1) AND (another_one = 2)'
expect(active_query.where(no_attribute: 1, 'another_one' => 2).to_s).to eq(expected)
end

it 'uses the given key in an in condition' do
expected = 'SELECT Id FROM table_name WHERE (no_attribute IN (1,2))'
expect(active_query.where(no_attribute: [1, 2]).to_s).to eq(expected)
end
end
end

describe '#not' do
Expand Down

0 comments on commit fa321b5

Please sign in to comment.