Reputation: 91
Here is the general theme I want to play with:
I am trying to do this by doing the following:
as("parent")
select("parent)
Example:
g.addV("parent").property("parent_value","value1").as("parent")
.addE("parent_to")
.addV("child").property("child_value","value2")
.select("parent")
.addE("parent_to")
.addV("child").property("child_value","value3")
Problem is this gives me 1 parent vertex with two child vertices, but the edges loop back to and from the parent, leaving the child vertices "orphaned".
I have linked a post that gives me a working pattern, but is it really the best way to handle hierarchy in one query without need for recursion? Other QA
Note: Added a level for example's sake
g.addV("parent").as("parent")
.and(
addV("child").property("child_value","value2")
.addE("parent_to").from("parent"),
addV("child").property("child_value","value3").as("child3").and(
addV("grandchild").property("gchild_value","value4").addE("parent_to").from("child3"),
addV("grandchild").property("gchild_value","value5").addE("parent_to").from("child3")
)
.addE("parent_to").from("parent")
)
Upvotes: 1
Views: 417
Reputation: 6341
Your query is close, it is just missing specifying the from() or to() steps to tell addE() which vertices to connect. I this case you probably want to use to() step as shown here.
g.addV("parent").
property("parent_value", "value1").as("parent").
addE("parent_to").to(addV("child").property("child_value", "value2")).
select("parent").
addE("parent_to").to(addV("child").property("child_value", "value3"))
Upvotes: 1