neo4j-scala icon indicating copy to clipboard operation
neo4j-scala copied to clipboard

Extending NodeRelationshipMethods

Open stephenmuss opened this issue 10 years ago • 4 comments

It would be extremely useful to extend OutgoingRelationshipBuilder and IncomingRelationshipBuilder in order to be able to determine whether a node has a specific relationship and to get nodes at the other end of the relationship.

I am unsure about the methods in terms of whether they should use symbols or English but they should be idiomatic enough to be easily read.

For example, to determine whether a node has a relationship we could use something along the lines of:

node --> "SOME_RELATIONSHIP" exists // English
node --> "SOME_RELATIONSHIP" ? // Symbol

node <-- "SOME_RELATIONSHIP" exists
node <-- "SOME_RELATIONSHIP" ?

To get nodes at the other end of the relationship(s)

node --> "SOME_RELATIONSHIP" getNodes
node --> "SOME_RELATIONSHIP" *

node <-- "SOME_RELATIONSHIP" getNodes
node <-- "SOME_RELATIONSHIP" *

The snippets are not necessarily using the method names I would suggest but merely for example. In any case they would be quite useful.

Currently, to achieve the same result it would be necessary to write something like this:

val rels = node.getRelationships(Direction.OUTGOING, DynamicRelationshipType.withName("SOME_RELATIONSHIP"))
val nodes = rels.toList.map((rel: Relationship) => rel.getOtherNode(node))

val hasRel = node.hasRelationship(DynamicRelationshipType.withName("SOME_RELATIONSHIP"), Direction.OUTGOING)

I'd be happy to submit a pull request for this.

stephenmuss avatar Aug 05 '14 07:08 stephenmuss

Some prefer symbols, some (like me) prefer English. I think that the '?' is quite obvious, but a '*' is questionable. However, it is possible to provide both, as we are creating a common library.

FaKod avatar Aug 05 '14 09:08 FaKod

I agree that using * is probably not the greatest idea but couldn't think of an alternative for the sake of the example.

Providing both the English methods and their symbol equivalents seems like it could be the way to go.

What are your ideas as an alternative to *?

stephenmuss avatar Aug 05 '14 10:08 stephenmuss

Hi Christopher, now that 0.3.1-SNAPSHOT is out I wouldn't mind having a crack at this. What would your preference be for symbol method names for node <-- "SOME_RELATIONSHIP" getNodes or even for the English ones?

stephenmuss avatar Oct 29 '14 10:10 stephenmuss

I think * and getNodes is ok.

FaKod avatar Oct 31 '14 07:10 FaKod