I want to run directly Cypher queries in rails don't want to use ORM style because I have long queries which I made on neo4j console and when I am trying to change into orm style its not behaving as expected
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 and Neo4j._query etc
Any Help?
Edit: How to write it in ORM style may be I was doing something wrong?
Here is
Querystyle as requested in comments. With a query like this, though, you don't get much benefit from this style unless maybe you're passing partialQueryobjects around. You probably want to stick to a Cypher query defined in a Ruby heredoc.You need the
breakin there to keep thematchclauses from grouping, though that's because of a design decision that I've wanted to reverse for a while now.Also, I'm thinking that there should be a
with_distinctmethod becauseDISTINCT(IIRC) applies to the whole set of columns.