@@ -149,6 +149,16 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
149149 .subquery ()
150150 )
151151
152+ children_subquery = (
153+ select (
154+ child .pid ,
155+ func .jsonb_agg (child .word ).filter (child .word .isnot (None )).label ('other_words' )
156+ )
157+ .where (child .pid .isnot (None ))
158+ .group_by (child .pid )
159+ .subquery ()
160+ )
161+
152162 # 创建子查询来获取数据源名称
153163 datasource_names_subquery = (
154164 select (
@@ -167,10 +177,13 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
167177 Terminology .description ,
168178 Terminology .specific_ds ,
169179 Terminology .datasource_ids ,
170- func . jsonb_agg ( child . word ). filter ( child . word . isnot ( None )). label ( ' other_words' ) ,
180+ children_subquery . c . other_words ,
171181 func .jsonb_agg (CoreDatasource .name ).filter (CoreDatasource .id .isnot (None )).label ('datasource_names' )
172182 )
173- .outerjoin (child , and_ (Terminology .id == child .pid ))
183+ .outerjoin (
184+ children_subquery ,
185+ Terminology .id == children_subquery .c .pid
186+ )
174187 # 关联数据源名称子查询和 CoreDatasource 表
175188 .outerjoin (
176189 datasource_names_subquery ,
@@ -181,7 +194,14 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
181194 CoreDatasource .id == datasource_names_subquery .c .ds_id
182195 )
183196 .where (and_ (Terminology .id .in_ (paginated_parent_ids ), Terminology .oid == oid ))
184- .group_by (Terminology .id , Terminology .word )
197+ .group_by (Terminology .id ,
198+ Terminology .word ,
199+ Terminology .create_time ,
200+ Terminology .description ,
201+ Terminology .specific_ds ,
202+ Terminology .datasource_ids ,
203+ children_subquery .c .other_words
204+ )
185205 .order_by (Terminology .create_time .desc ())
186206 )
187207
0 commit comments