@@ -49,7 +49,12 @@ async def get_descendents(
49
49
uuid : shared_data_models .UUID , db : Repository = Depends ()
50
50
) -> List [source_type ]:
51
51
return await db .get_docs (
52
- doc_filter = {source_attribute : uuid }, doc_type = source_type
52
+ # !!!!
53
+ # source_attribute has list values sometimes (for models that reference a list of other objects)
54
+ # mongo queries just so happen have the semantics we want
55
+ # a.i. list_attribute: some_val means "any value in list_attribute is equal to some_val"
56
+ doc_filter = {source_attribute : uuid },
57
+ doc_type = source_type ,
53
58
)
54
59
55
60
return get_descendents
@@ -60,14 +65,18 @@ async def get_descendents(
60
65
if len (uuid_field_type .metadata ):
61
66
parent_type = uuid_field_type .metadata [0 ] # convention
62
67
63
- router .add_api_route (
64
- f"/{ to_snake (parent_type .__name__ )} /{{uuid}}/{ to_snake (model .__name__ )} " ,
65
- response_model = List [model ],
66
- operation_id = f"get{ model .__name__ } In{ parent_type .__name__ } " ,
67
- summary = f"Get { model .__name__ } In { parent_type .__name__ } " ,
68
- methods = ["GET" ],
69
- endpoint = make_reverse_link_handler (uuid_field_name , model ),
70
- )
68
+ # List validators (e.g. MinLength) are also set in the type.metadata list
69
+ # -> only generate backlinks for types that have metadata that is also one of the exposed types
70
+ # ? Maybe find a better way to wrap "foreign key"-type relationships, like a custom generic similar to List so we can also drop the [0] convention?
71
+ if parent_type in models_public :
72
+ router .add_api_route (
73
+ f"/{ to_snake (parent_type .__name__ )} /{{uuid}}/{ to_snake (model .__name__ )} " ,
74
+ response_model = List [model ],
75
+ operation_id = f"get{ model .__name__ } In{ parent_type .__name__ } " ,
76
+ summary = f"Get { model .__name__ } In { parent_type .__name__ } " ,
77
+ methods = ["GET" ],
78
+ endpoint = make_reverse_link_handler (uuid_field_name , model ),
79
+ )
71
80
72
81
73
82
def make_router () -> APIRouter :
0 commit comments