-
Notifications
You must be signed in to change notification settings - Fork 5
Bidirectional Connections
If a Vertex is loaded, its edges are present in the ActiveOrient::Model
-Record.
Lets focus on a sample Vertex
> v => <V2:0x00000000032c8c58 @metadata={:type=>"d", :class=>"v2", :version=>2,
:fieldTypes=>"in_e2=g", :cluster=>36, :record=>0,
:edges=>{:in=>["e2"], :out=>[]}},
@attributes={:node=>4, :in_e2=>["#52:0"]}>
ActiveOrient
provides two representations of connected Edges: The :edges
Metadata property
and the named attribute in_e2
. The connected Edge-Classes and even the rid's
if the
Edges are present.
After loading the vertex, no information is provided about connected Vertices (Nodes).
Vertex.nodes
changes that.
Vertex.nodes ( :in -or- :out , via: {Edge-Class -or- Regular-Expression}, where: {a conditon}, expand: {true -or- false} )
After checking the provided via:
parameter, Vertex.node
delegates the task to OrientQuery.
> v.nodes( :in, via: /e/, expand: true) &.to_human
INFO->select expand ( inE('e2').out ) from #36:0
=> ["<V1[25:0]: out: {E2=>10}, item : 1>"]
> pp v.nodes( :in, via: /e/, expand: true).nodes( :out, via: /e2/ , expand: true) &.to_human
INFO->select expand ( inE('e2').out ) from #36:0
INFO->select expand ( outE('e2').in ) from #25:0
[["<V2[33:0]: in: {E2=>1}, node : 1>",
"<V2[34:0]: in: {E2=>1}, node : 2>",
"<V2[35:0]: in: {E2=>1}, node : 3>",
"<V2[36:0]: in: {E2=>1}, node : 4>",
"<V2[37:0]: in: {E2=>1}, node : 5>",
"<V2[38:0]: in: {E2=>1}, node : 6>",
"<V2[39:0]: in: {E2=>1}, node : 7>",
"<V2[40:0]: in: {E2=>1}, node : 8>",
"<V2[33:1]: in: {E2=>1}, node : 9>",
"<V2[34:1]: in: {E2=>1}, node : 10>"]]
> pp v.nodes( :in, via: /e/, expand: true)
.nodes( :out, via: /e2/ , expand: true, where:'node>6')
.map &:to_human
INFO->select expand ( inE('e2').out ) from #36:0
INFO->select expand ( outE('e2').in[ node>6 ] ) from #25:0
[["<V2[39:0]: in: {E2=>1}, node : 7>",
"<V2[40:0]: in: {E2=>1}, node : 8>",
"<V2[33:1]: in: {E2=>1}, node : 9>",
"<V2[34:1]: in: {E2=>1}, node : 10>"]]
Unfortunately, this approach fires one query per traversed layer.
Instead a Regular Expression an Edge-Class can be provided to :via
, ie. v.nodes :in, via: E2
note1: Vertex.nodes() returns a ActiveSupport::Array
. Any method of V
is delegated and thus applied to the collection.
note2 Vertex.match provides an alternative approach to access connected data.
note3 The approach of nodes focuses on outE().in and inE().out
The database offers additional traversal options
-
outE
: Vertex to outgoing edges -
inE
: Vertex to incoming edges -
bothE
: Vertex to all edges -
inV
: Edge to Vertex (end point) -
outV
: Edge to Vertex (starting point) -
bothV
: Edge to Vertex (both sizes) -
out
: Vertex to Vertex (outgoing edges). Same as outE().inV() -
in
: Vertex to Vertex (incoming edges). Same as outE().inV() -
both
: Vertex to Vertex (all directions)
Overview
Data Management
- Joining Tables, embedded Lists
- Links and Link Lists
- Relations
- Bidirectional Connections
- Working with Hashes
Public API
- Database
- Model CRUD
Misc