Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/active_cypher/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ def where(conditions)
case conditions
when Hash
conditions.each do |key, value|
expr = Cyrel.prop(node_alias, key).eq(value)
if value.is_a?(Array)
expr = Cyrel::Expression::Comparison.new(
Cyrel.prop(node_alias, key),
:IN,
value
)
else
expr = Cyrel.prop(node_alias, key).eq(value)
end
new_query = new_query.where(expr)
end
when Cyrel::Expression::Base
Expand Down
3 changes: 3 additions & 0 deletions lib/active_cypher/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

module ActiveCypher
class Relationship
# Define connects_to_mappings as a class attribute to match ActiveCypher::Base ?
# class_attribute :connects_to_mappings, default: { reading: :primary, writing: :primary }
Comment on lines +32 to +33

# --------------------------------------------------------------
# Mix‑ins
# --------------------------------------------------------------
Expand Down
36 changes: 36 additions & 0 deletions test/active_cypher/comparison_arrays_should_in_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'test_helper'
require 'cyrel'

module Cyrel
class ComparisonArraysShouldIn < ActiveSupport::TestCase
test 'where with eq string should = string' do
alice = PersonNode.create(name: 'Alice')
bob = PersonNode.create(name: 'Bob')
charlie = PersonNode.create(name: 'Charlie')
Comment on lines +9 to +11
cypher_string, params_hash = PersonNode.where(name: 'Alice').cyrel_query.to_cypher
expected_cypher = <<~CYPHER.chomp.strip
MATCH (n:Person)
WHERE (n.name = $p1)
RETURN n, __NODE_ID__(n) AS internal_id
CYPHER
expected_params = { p1: 'Alice' }
assert_equal [expected_cypher, expected_params], [cypher_string, params_hash]
end

test 'where with eq array should IN array' do
alice = PersonNode.create(name: 'Alice')
bob = PersonNode.create(name: 'Bob')
charlie = PersonNode.create(name: 'Charlie')
Comment on lines +23 to +25
cypher_string, params_hash = PersonNode.where(name: ['Alice', 'Bob']).cyrel_query.to_cypher
expected_cypher = <<~CYPHER.chomp.strip
MATCH (n:Person)
WHERE (n.name IN $p1)
RETURN n, __NODE_ID__(n) AS internal_id
CYPHER
expected_params = { p1: ['Alice', 'Bob'] }
assert_equal [expected_cypher, expected_params], [cypher_string, params_hash]
end
end
end