neo4j - how to match relationships with multiple properties passed as a query parameter? -
let's have next info model:
(user)-[r:has_permissions]->(n)
, properties of 'r' permissions in boolean values, view=true, create=true.
i want find users have permissions entity, passed query parameter.
naively want like:
match (u:user)-[r:has_permissions {permissions}]->(n) homecoming u
, know isn't right {permissions}
can used create
statement..
the passed permissions parameter map, {view: true}
i'm thinking of like:
match (u:user)-[r:has_permissions]->(n) all(p in {permissions} r.{p} = {permissions}.p) homecoming u
obviously won't work permissions property map , not array , need access it's keys , values somehow.
am in right direction ? how can accomplish i'm looking ?
you can pass each of properties of permissions
variable independently.
match (u:user)-[r:has_permissions { view: {view}, create: {create} }]->(n) homecoming u
then pass in parameters view
, create
.
if don't know permissions properties may be, handle in app. in ruby, i'd this:
def permissions_parameter(permissions) permission_keys = [] permission_values = [] permissions.each |k, v| permission_keys.push("r.#{k}: {#{k}}") permission_values.push("'#{k}': '#{v}'") end permission_keys_cypher = permission_keys.join(', ') permission_params_cypher = permission_values.join(', ') [permission_keys_cypher, permission_params_cypher] end permissions = permissions_parameter({ create: true, view: true }) puts "match (u:user)-[r:has_permissions { #{permissions[0]} }]->(n) homecoming u" # match (u:user)-[r:has_permissions { r.create: {create}, r.view: {view} }]->(n) homecoming u puts "params: #{permissions[1]}" # params: 'create': 'true', 'view': 'true'
neo4j cypher
No comments:
Post a Comment