I have been playing around with people graphs and determining ancestors and descendants. I've been banging my head trying to figure out how to get a set of records and their ancestors/descendants (see here <https://groups.google.com/forum/#!topic/orient-database/4ltzMIfg7rk>). When I got the ancestors, I was only getting back the record ids. I then had to do a separate query to get the records for those rids. I now see that was the wrong approach. OrientDB gives us FETCHPLAN to grab the json of the record and levels of traversal through the edges.
Here is what I have so far: *Person* extends V Person.Name = String Person.Age = Integer *IsChildOf* extends E Here is a sample graph I've constructed: <https://lh3.googleusercontent.com/-eYDwxm1ZycQ/VdVAG5JIEmI/AAAAAAAAGB4/vzEYN7c88GE/s1600/familytree.jpg> Now, I want to run a query to get Frank and his ancestral tree, so I've tried running: select *, @this.toJSON('fetchPlan:[*]out_IsChildOf:-1 [*]in_IsChildOf*:-2') from Person where Name = "Frank" This gives me the intended output: { "Name": "Frank", "Age": 58, "out_IsChildOf": [ { "out": "#12:0", "in": { "Name": "Bob", "Age": 80, "in_IsChildOf": [ "#13:6" ], "out_IsChildOf": [ { "out": "#12:5", "in": { "Name": "Gladis", "Age": 98, "in_IsChildOf": [ "#13:10" ] } } ] } }, { "out": "#12:0", "in": { "Name": "Jane", "Age": 75, "in_IsChildOf": [ "#13:7" ] } } ] } Great! Now, let's try and find the ancestral tree of someone a bit deeper, let's pick Mary select *, @this.toJSON('fetchPlan:[*]out_IsChildOf:-1 [*]in_IsChildOf*:-2') from Person where Name = "Mary" Uh oh { "Name": "Mary", "Age": 24, "out_IsChildOf": [ { "out": "#12:4", "in": { "Name": "Susan", "Age": 57, "in_IsChildOf": [ { "out": { "Name": "Tony", "Age": 29, "out_IsChildOf": [ { "out": "#12:2", "in": { "Name": "Frank", "Age": 58, "out_IsChildOf": [ { "out": "#12:0", "in": { "Name": "Bob", "Age": 80, "in_IsChildOf": [ "#13:6" ], "out_IsChildOf": [ { "out": "#12:5", "in": { "Name": "Gladis", "Age": 98, "in_IsChildOf": [ "#13:10" ] } } ] } }, { "out": "#12:0", "in": { "Name": "Jane", "Age": 75, "in_IsChildOf": [ "#13:7" ] } } ], "in_IsChildOf": [ "#13:0", { "out": { "Name": "Steven", "Age": 25, "out_IsChildOf": [ { "out": "#12:3", "in": "#12:1" }, "#13:3" ], "in_IsChildOf": [ { "out": { "Name": "Dave", "Age": 12, "out_IsChildOf": [ "#13:8", { "out": "#12:7", "in": { "Name": "Amy", "Age": 32, "in_IsChildOf": [ "#13:9" ] } } ] }, "in": "#12:3" } ] }, "in": "#12:0" }, { "out": "#12:4", "in": "#12:0" } ] } }, "#13:1" ] }, "in": "#12:1" }, "#13:2", "#13:4" ] } }, "#13:5" ] } What happened? Why is the fetch plan grabbing the in_IsChildOf when I thought I explicitly informed it to ignore that path via the ' [*]in_IsChildOf*:-2. How do you have a fetch plan only follow a single relationship type in a single direction, ignoring all other relationships? Side Question: Why does the fetch plan not return a record rid? How are you supposed to resolve circular references without knowing what record corresponds with the rid? -- --- You received this message because you are subscribed to the Google Groups "OrientDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
