Variable Relationships like timestamp or other ID #96
-
Is there a way to create a relationship like a timestamp relationship with the gogm library? My use case isn't specifically timestamp, but a custom ID. For example, having a relationship between a repository and dependency, but in the relationship name, depicting which environment (dev, qa, uat, prod) has that dependency |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
GoGM supports edges with additional properties ("special" edges). Special edges work a little different from regular relationships though. Take a look at the example from the ReadMe as an example: //structs for the example (can also be found in decoder_test.go)
type VertexA struct {
// provides required node fields
gogm.BaseNode
TestField string `gogm:"name=test_field"`
TestTypeDefString tdString `gogm:"name=test_type_def_string"`
TestTypeDefInt tdInt `gogm:"name=test_type_def_int"`
MapProperty map[string]string `gogm:"name=map_property;properties"`
SliceProperty []string `gogm:"name=slice_property;properties"`
SingleA *VertexB `gogm:"direction=incoming;relationship=test_rel"`
ManyA []*VertexB `gogm:"direction=incoming;relationship=testm2o"`
MultiA []*VertexB `gogm:"direction=incoming;relationship=multib"`
SingleSpecA *EdgeC `gogm:"direction=outgoing;relationship=special_single"`
MultiSpecA []*EdgeC `gogm:"direction=outgoing;relationship=special_multi"`
}
type VertexB struct {
// provides required node fields
gogm.BaseNode
TestField string `gogm:"name=test_field"`
TestTime time.Time `gogm:"name=test_time"`
Single *VertexA `gogm:"direction=outgoing;relationship=test_rel"`
ManyB *VertexA `gogm:"direction=outgoing;relationship=testm2o"`
Multi []*VertexA `gogm:"direction=outgoing;relationship=multib"`
SingleSpec *EdgeC `gogm:"direction=incoming;relationship=special_single"`
MultiSpec []*EdgeC `gogm:"direction=incoming;relationship=special_multi"`
}
type EdgeC struct {
// provides required node fields
gogm.BaseNode
Start *VertexA
End *VertexB
Test string `gogm:"name=test"`
}
func (e *EdgeC) GetStartNode() interface{} {
return e.Start
}
func (e *EdgeC) GetStartNodeType() reflect.Type {
return reflect.TypeOf(&VertexA{})
}
func (e *EdgeC) GetEndNode() interface{} {
return e.End
}
func (e *EdgeC) GetEndNodeType() reflect.Type {
return reflect.TypeOf(&VertexB{})
} The above example has a special edge type Currently, special edges have the additional requirement that they implement the special edge interface requiring the edge to implement the Other then that hurdle, special relationships can be treated almost exactly like a regular node. |
Beta Was this translation helpful? Give feedback.
GoGM supports edges with additional properties ("special" edges). Special edges work a little different from regular relationships though. Take a look at the example from the ReadMe as an example: