Skip to content

Commit 773efc5

Browse files
committed
attempt to get relay nested model retrieval
1 parent 17e85aa commit 773efc5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

opensensor/collection_apis.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def get_nested_fields(model: Type[BaseModel]):
200200

201201

202202
def create_nested_pipeline(model: Type[BaseModel], prefix=""):
203+
logger.debug(f"Creating nested pipeline for model: {model.__name__}, prefix: {prefix}")
203204
nested_fields = get_nested_fields(model)
204205
pipeline = {}
205206
match_conditions = {}
@@ -218,10 +219,16 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
218219
if field_name in nested_fields:
219220
if get_origin(field_type.type_) is List:
220221
nested_pipeline, nested_match = create_nested_pipeline(
221-
nested_fields[field_name], "$$item."
222+
nested_fields[field_name], "" # Empty prefix for list items
222223
)
223224
pipeline[field_name] = {
224-
"$map": {"input": f"${full_field_name}", "as": "item", "in": nested_pipeline}
225+
"$map": {
226+
"input": f"${full_field_name}",
227+
"as": "item",
228+
"in": {
229+
k: f"$item.{v.replace('$', '')}" for k, v in nested_pipeline.items()
230+
},
231+
}
225232
}
226233
match_conditions[full_field_name] = {"$exists": True, "$ne": []}
227234
else:
@@ -236,6 +243,10 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
236243
pipeline[field_name] = f"${full_field_name}"
237244
match_conditions[full_field_name] = {"$exists": True}
238245

246+
logger.debug(f"Field: {field_name}, Full field name: {full_field_name}")
247+
logger.debug(f"Resulting pipeline part: {pipeline[field_name]}")
248+
249+
logger.debug(f"Final pipeline for {model.__name__}: {pipeline}")
239250
return pipeline, match_conditions
240251

241252

0 commit comments

Comments
 (0)