Reputation: 67
I have nodes with Product Information (P). Every time a user likes the product, relationship [L] is created connecting user (U)->[L]->[P]
Now I need to retrieve a set of Product nodes based on specific condition, but also need to return additional information that whether they are liked by a specific user or not.
So if the Product Structure is like
{ Product Name, Price }
If lets say, 1 out of the 3 products in question is liked by user X, the result set I need may look something like this
[{Product1, 29.00, true}, {Product2, 39.00, false}, {Product3, 25.00, false}]
Here true refers to the fact that user has liked Product1 and has not liked Product2.
I am not sure how to write such a query that includes this additional information of whether the returned nodes are liked or not
Upvotes: 0
Views: 87
Reputation: 11216
I think something like this will suit your needs.
Match all the products. You will want to scope this match down in some way.
Optionally match user likes per product.
Return collection of maps that contain name, price and like status.
match (p:Product)
optional match (u:User)-[:LIKES]->p
with {product:p.name, price:p.price, like: case when u is null then false else true end} as Product_Detail
return collect(Product_Detail)
Upvotes: 3