neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

Finding nodes with boolean properties returns empty array #1573

Closed OpenCoderX closed 4 years ago

OpenCoderX commented 4 years ago

It seems there is a bug when searching for properties that have boolean values. I was expecting the second query to return 2. The first two queries demonstrate that the where/count combination works when calling on a Class but fails when using an instance and an association chain. The 3rd query demonstrates that there should be two records that are counted, bsed on the value of the core_dictionary property. I noticed some old issues related to this: 951 and 294

See the following pry session:

Additional information which could be helpful if relevant to your issue:

Code example (inline, gist, or repo)

[36] pry(main)> ItemClassGuide.where(core_dictionary: true).count
 CYPHER 
  MATCH (result_itemclassguide2:`ItemClassGuide`)
  WHERE (result_itemclassguide2.core_dictionary = {result_itemclassguide2_core_dictionary})
  RETURN count(result_itemclassguide2) AS result_itemclassguide2 | {:result_itemclassguide2_core_dictionary=>true}
 HTTP REQUEST: 3ms POST http://:7474/db/data/transaction/commit (1 bytes)
=> 7
[37] pry(main)> @item_class.item_class_guides(:icg).where(core_dictionary: true).count
 ItemClass#item_class_guides 
  MATCH (itemclass72578)
  WHERE (ID(itemclass72578) = {ID_itemclass72578})
  MATCH (itemclass72578)-[rel1:`item_class_guide`]->(icg:`ItemClassGuide`)
  WHERE (icg.core_dictionary = {icg_core_dictionary})
  RETURN count(icg) AS icg | {:icg_core_dictionary=>true, :ID_itemclass72578=>72578}
 HTTP REQUEST: 3ms POST http://:7474/db/data/transaction/commit (1 bytes)
=> 0
[38] pry(main)> @item_class.item_class_guides(:icg).all
 ItemClass#item_class_guides 
  MATCH (itemclass72578)
  WHERE (ID(itemclass72578) = {ID_itemclass72578})
  MATCH (itemclass72578)-[rel1:`item_class_guide`]->(icg:`ItemClassGuide`)
  RETURN icg | {:ID_itemclass72578=>72578}
 HTTP REQUEST: 3ms POST http://:7474/db/data/transaction/commit (1 bytes)
=> #<QueryProxy ItemClass#item_class_guides [#<ItemClassGuide uuid: "8e5b07e2-6dbb-47de-9280-f86014804e78", core_dictionary: true, created_at: Sun, 01 Jan 2017 18:23:04 +0000, description: "testasdf", description_lower: "testasdf", identifier: "SF#-0001-d21b142a150", identifier_lower: "sf#-0001-d21b142a150", status: 1, unspsc: nil, unspsc_extension: nil, updated_at: Sat, 16 Mar 2019 20:44:43 +0000, workflow_state: "in_process">, #<ItemClassGuide uuid: "889a9306-05a5-41ad-9b0f-fac6fec58be7", core_dictionary: true, created_at: Sun, 01 Jan 2017 18:19:18 +0000, description: "test", description_lower: "test", identifier: "SF#-0001-0bf210910cb", identifier_lower: "sf#-0001-0bf210910cb", status: 1, unspsc: nil, unspsc_extension: nil, updated_at: Sat, 16 Mar 2019 20:44:43 +0000, workflow_state: "in_process">]>
[39] pry(main)> 

Runtime information:

Neo4j database version: neo4j gem version: 9.6.0 neo4j-core gem version: 9.0.0

klobuczek commented 4 years ago

@OpenCoderX could you create a minimal example with a complete code. ActiveNode definition, data creation and retrieval to demonstrate this? There are many factors that play a role.

OpenCoderX commented 4 years ago

The cypher appears to be correct, maybe this is a problem with my server.

OpenCoderX commented 4 years ago

It seems like when the node is found with find_by and defaults are applied, the attributes that have their values changed when defaults are set are not marked as changed attributes.