如何建立条件关系? [英] How to create conditional relationships?

查看:91
本文介绍了如何建立条件关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由组织运行的系统来实现某个功能,因此我有以下关系:

I have a system that is run by an organization to implement a certain function, thus I have the relationship:

组织→职能→系统

但有时功能仍然未知,在这种情况下,我想将系统直接绑定到组织:

but sometimes the function remains unknown, in which case I want to bind the system directly to the organization:

组织→系统

这种东西怎么写?

系统包含用于创建这些关系的属性,例如

the System contains attributes that are used for creating these relationships e.g.

create (s:System {id: 'x', Organization: 'MST', Function: 'CM'})

create (s:System {id: 'x', Organization: 'MST'})

这意味着我可以找到这样的节点:

which means I can find the nodes like this:

match (s:System), (o:Organization {Code: s.Organization})
optional match (f:Function {Code: s.Function})

...但是我如何建立关系?

...but how do I create the relationship?

推荐答案

我找到了 Mark Needham 的帖子:

I found Mark Needham's post:

http://www.markhneedham.com/blog/2014/06/17/neo4j-load-csv-handling-conditionals/

...它提供了一种折磨人的语法,但提供了一个解决方案.有没有更好的方法来实现这一点?

...which offers a torturous syntax but provides a solution. Is there a nicer way to accomplish this?

match (s:System), (o:Organization {Code: s.Organization}) 
optional match (d:Function {Code: s.Function}) 
foreach (n in (case when s.Function is null then [1] else [] end) | 
  create (o)-[:Runs]->(s)
) 
foreach (n in (case when s.Function is not null then [1] else [] end) | 
  create (o)-[:Function]->(f)-[:SupportedBy]->(s)
);

这篇关于如何建立条件关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆