Reputation: 1541
class Picture
property :name
property :user_ids
serialize :user_ids
end
Picture.create(name: '1', user_ids: [1,4,5])
How to find all pictures having user id 1 in user_ids property
I am trying this in way:
Picture.as(:p).where('ALL(x IN [1] WHERE x IN p.user_ids)')
Neo4j.rb version - neo4j (8.0.13)
Neo4j - 3.1.1 Enterprise
But its not working. Or there is any better way to store array and query it as well, Any help would be very appreciable
EDIT: Shown Bruno's Example & My Node description above I have used example node
@Bruno example is working fine.
Here is my Neo4j node view
match (p:Place) where ALL(x IN [14] WHERE x IN p.from_airport_ids) return p
This is not working in my case
class Place
include Neo4j::ActiveNode
property :name
property :from_airport_ids
serialize :from_airport_ids
end
Create Place through API
{
"place":{
"name":"Name",
"from_airport_ids":[14,44,67]
}
}
Is it related to how my array values stored in node and how @Bruno example values are stored?
Upvotes: 2
Views: 268
Reputation: 16375
Try changing your query to:
Picture.as(:p).where('1 IN p.user_ids)')
That is: match all p
s where p.user_ids
contains 1.
Also, I believe you should store relationships between :User
and :Picture
nodes instead of an array of ids into :Picture
. It's a more graph-way to do things.
Something like
-[:CONNECTED_TO]->(:User {id:1})
/
(:Picture)-[:CONNECTED_TO]->(:User {id:2})
\
-[:CONNECTED_TO]->(:User {id:3})
Upvotes: 2