Skip to content

Commit

Permalink
Merge pull request #35 from doctolib/BIC-193-FIX-NOT
Browse files Browse the repository at this point in the history
[BIC-1903] Fix use of properties_always_exists_in_document for not match case
  • Loading branch information
pimpin authored Mar 1, 2024
2 parents 3319a69 + 3c40c35 commit 31655d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/couchbase-orm/utilities/query_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def build_not_match(key, value)
key = "meta().id" if key.to_s == "id"
case
when value.nil? && use_is_null
"#{key} IS NULL"
"#{key} IS NOT NULL"
when value.nil? && !use_is_null
"#{key} IS VALUED"
when value.is_a?(Array) && value.include?(nil)
Expand Down
10 changes: 10 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,19 @@ class InvalidNested < CouchbaseOrm::NestedDocument
expect(where_clause.to_n1ql).to include("AND name IS NOT VALUED")
end

it 'Uses VALUED when properties_always_exists_in_document = false' do
where_clause = BaseTest.where.not(name: nil)
expect(where_clause.to_n1ql).to include("AND name IS VALUED")
end

it 'Uses IS NULL when properties_always_exists_in_document = true' do
where_clause = BaseTestWithPropertiesAlwaysExistsInDocument.where(name: nil)
expect(where_clause.to_n1ql).to include("AND name IS NULL")
end

it 'Uses IS NOT NULL when properties_always_exists_in_document = true' do
where_clause = BaseTestWithPropertiesAlwaysExistsInDocument.where.not(name: nil)
expect(where_clause.to_n1ql).to include("AND name IS NOT NULL")
end
end
end

0 comments on commit 31655d3

Please sign in to comment.