1
votes

let's say you have the following relationship:

Author-----wrote---->Article

and you want to prepare a report about each author and how many articles he has wrote and the date of his last article, the proplem appears when there are authors who wrote no articles, they will be dropped when you pass the 'wrote' pipe and i want to include them with '0' in 'count' column and 'N/A' in 'date' column, so my quesion is how to solve this problem ?

1

1 Answers

2
votes

I assume that you are still working with TinkerPop 2.x given your usage of OrientDB so I will answer in that fashion. You need to do something like:

gremlin> g = new TinkerGraph()                        
==>tinkergraph[vertices:0 edges:0]
gremlin> bill = g.addVertex([author:'bill',type:'author'])
==>v[0]
gremlin> amy = g.addVertex([author:'amy',type:'author'])  
==>v[1]
gremlin> book1 = g.addVertex([book:1,type:'book'])        
==>v[2]
gremlin> book2 = g.addVertex([book:2,type:'book'])        
==>v[3]
gremlin> bill.addEdge('wrote',book1)                      
==>e[4][0-wrote->2]
gremlin> bill.addEdge('wrote',book2)
==>e[5][0-wrote->3]
gremlin> g.V.has('type','author').transform{[it, it.outE('wrote').count()]}
==>[v[0], 2]
==>[v[1], 0]