mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-06-12 16:53:35 +00:00
Use first element in a tag as a local relation field
This commit is contained in:
@@ -78,9 +78,9 @@ func createAggregateLoad(db *mongox.Database, target interface{}, composed *quer
|
|||||||
panic("there is no foreign field")
|
panic("there is no foreign field")
|
||||||
}
|
}
|
||||||
|
|
||||||
preloadName := strings.TrimSpace(preloadData[0])
|
localField := strings.TrimSpace(preloadData[0])
|
||||||
if len(preloadName) == 0 {
|
if len(localField) == 0 {
|
||||||
preloadName = jsonName
|
localField = "_id"
|
||||||
}
|
}
|
||||||
|
|
||||||
foreignField := strings.TrimSpace(preloadData[1])
|
foreignField := strings.TrimSpace(preloadData[1])
|
||||||
@@ -106,7 +106,7 @@ func createAggregateLoad(db *mongox.Database, target interface{}, composed *quer
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, preload := range preloads {
|
for _, preload := range preloads {
|
||||||
if preload != preloadName {
|
if preload != jsonName {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,9 +119,8 @@ func createAggregateLoad(db *mongox.Database, target interface{}, composed *quer
|
|||||||
|
|
||||||
typ := el.Field(i).Type()
|
typ := el.Field(i).Type()
|
||||||
lookupCollection := db.GetCollectionOf(reflect.Zero(typ).Interface())
|
lookupCollection := db.GetCollectionOf(reflect.Zero(typ).Interface())
|
||||||
lookupVars := primitive.M{"selector": "$_id"}
|
lookupVars := primitive.M{"selector": "$" + localField}
|
||||||
lookupPipeline := primitive.A{
|
lookupPipeline := primitive.A{
|
||||||
// todo: make match from composed query
|
|
||||||
primitive.M{"$match": primitive.M{"$expr": primitive.M{"$eq": primitive.A{"$" + foreignField, "$$selector"}}}},
|
primitive.M{"$match": primitive.M{"$expr": primitive.M{"$eq": primitive.A{"$" + foreignField, "$$selector"}}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user