Skip to content

Commit

Permalink
Merge from victorspringer/victorspringer-collection-relate-fix
Browse files Browse the repository at this point in the history
Fixes Collection.Relate() [issue diegogub#42]
  • Loading branch information
victorspringer authored Mar 14, 2017
2 parents a49d222 + e0bd182 commit 862c842
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,15 @@ func (col *Collection) Save(doc interface{}) error {
}

// Save Edge into Edges collection
func (col *Collection) SaveEdge(doc interface{}, from string, to string) error {
func (col *Collection) SaveEdge(doc map[string]interface{}, from string, to string) error {
var err error
var res *nap.Response

doc["_from"] = from
doc["_to"] = to

if col.Type == 3 {
res, err = col.db.send("edge?collection="+col.Name+"&from="+from+"&to="+to, "", "POST", doc, &doc, &doc)
res, err = col.db.send("document?collection="+col.Name, "", "POST", doc, &doc, &doc)
} else {
return errors.New("Trying to save document into Edge-Collection")
}
Expand Down Expand Up @@ -206,13 +209,16 @@ func (col *Collection) Edges(start string, direction string, result interface{})
}

// Relate documents in edge collection
func (col *Collection) Relate(from string, to string, label interface{}) error {
func (col *Collection) Relate(from string, to string, label map[string]interface{}) error {
if col.Type == 2 {
return errors.New("Invalid collection to add Edge: " + col.Name)
}
if from == "" || to == "" {
return errors.New("from or to documents don't exist")
}
if label == nil {
label = make(map[string]interface{})
}

return col.SaveEdge(label, from, to)
}
Expand Down

0 comments on commit 862c842

Please sign in to comment.