我想在rails中直接运行Cypher查询不想使用ORM样式,因为我在neo4j控制台上进行了很长时间的查询,当我尝试更改为orm样式时,它的行为不符合预期
MATCH (n {name: 'MU1'})-[:connected_to*1..2 {status: 1}]->(sp:User),
(sp)<-[:owner_of|house_mate]-(place:Place)-[:owner_of|house_mate]->(c:User)
WHERE NOT (n)-[:house_mate]-(place)
MATCH
(place)-[tenant:owner_of|house_mate]->(u:User)
WITH DISTINCT place, type(tenant) AS type, u
WITH place, collect({type: type, u: u}) AS tenants
RETURN
place,
[tenant IN tenants WHERE tenant.type = 'owner_of' | [tenant.u]][0] AS owner,
[tenant IN tenants WHERE tenant.type = 'house_mate' | [tenant.u]] AS houseMatesArray
Neo4j.query和Neo4j._query等
任何帮助?
编辑:如何以ORM风格编写它可能是我做错了什么?
答案 0 :(得分:1)
ionic build browser --prod --release
答案 1 :(得分:1)
以下是评论中要求的Query
样式。但是,通过这样的查询,除非您传递部分Query
对象,否则您不会从这种风格中获益良多。您可能希望坚持使用Ruby heredoc中定义的Cypher查询。
Neo4j::ActiveBase.new_query
.match(n: {name: 'MU1'})
.match('(n)-[:connected_to*1..2 {status: ?}]->(sp:User)', 1)
.match('(sp)<-[:owner_of|house_mate]-(place:Place)-[:owner_of|house_mate]->(c:User)')
.where_not('(n)-[:house_mate]-(place)')
.break
.match('(place)-[tenant:owner_of|house_mate]->(u:User)')
.with('DISTINCT place, type(tenant) AS type, u')
.with(:place, tenants: 'collect({type: type, u: u})')
.pluck(:place,
owner: '[tenant IN tenants WHERE tenant.type = 'owner_of' | [tenant.u]][0]',
houseMatesArray: '[tenant IN tenants WHERE tenant.type = 'house_mate' | [tenant.u]]')
你需要break
来保持match
条款不被分组,尽管这是因为我现在想要扭转一段时间的设计决定。
另外,我认为应该有with_distinct
方法,因为DISTINCT
(IIRC)适用于整个列集。