Skip to content

Commit

Permalink
allowed using a Set of ids in where queries
Browse files Browse the repository at this point in the history
  • Loading branch information
klobuczek committed Jan 1, 2024
1 parent 543dfc7 commit 2c1cd1b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
This file should follow the standards specified on [http://keepachangelog.com/]
This project adheres to [Semantic Versioning](http://semver.org/).

## [12.0.0.beta.1] 2024-01-01

## Added

- removed deprecated usage of id (neo_id), replaced with element_id, requires neo4j-ruby-driver 5
- removed the possibility of using neo_id as id_property
- added id_property to relationships

## [11.5.0.beta.1] 2023-12-29

## Added
Expand Down
2 changes: 1 addition & 1 deletion lib/active_graph/core/query_clauses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def range_key_value_string(key, value, previous_keys, param)
end

def array_value?(value, is_set)
value.is_a?(Array) && !is_set
value.is_a?(Enumerable) && !is_set
end

def format_label(label_arg)
Expand Down
15 changes: 13 additions & 2 deletions lib/active_graph/node/query/query_proxy/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,26 @@ def new_for_key_and_value(model, key, value)

val = if !model
value
elsif key == model.id_property_name && value.is_a?(ActiveGraph::Node)
value.id
elsif key == model.id_property_name
try_id(value)
else
converted_value(model, key, value)
end

new(:where, ->(v, _) { {v => {key => val}} })
end

private def try_id(value)
case value
when Shared::Identity
value.id
when Enumerable
value.map(&method(:try_id))
else
value
end
end

def for_association(name, value, n_string, model)
neo_id = value.try(:neo_id) || value
fail ArgumentError, "Invalid value for '#{name}' condition" unless neo_id.is_a?(String)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_graph/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveGraph
VERSION = '11.5.0.beta.1'
VERSION = '12.0.0.beta.1'
end
4 changes: 4 additions & 0 deletions spec/e2e/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ def self.ordered_by_subject
it 'allows filtering and parametarizing by String and Hash in where' do
expect(Teacher.as(:teach).where('teach.name =~ $name', name: '.*Othmar.*').to_a).to eq([othmar])
end

it 'allows filtering by set' do
expect(Teacher.where(id: Set[samuels.id, othmar]).to_a).to include(samuels, othmar)
end
end

describe 'merge methods' do
Expand Down

0 comments on commit 2c1cd1b

Please sign in to comment.