fix: sort order in acupoints #14

Merged
amit merged 1 commits from fix/preserve-content-authoring-sort-order into main 2026-10-14 09:25:02 +00:00
2 changed files with 20 additions and 1 deletions

View File

@ -121,8 +121,17 @@ class ModuleSeeder:
from {self._schema}.content_items ci
join {self._schema}.attribute_definition_sets ads
on ads.id = ci.attribute_definition_set_id
left join {self._schema}.content_attributes ca
on ca.content_id = ci.id
and ca.attribute_definition_id = (
select id
from {self._schema}.attribute_definitions
where attribute_definition_set_id = ads.id
and code = 'sort_order'
limit 1
)
where ads.code = :definition_set_code
order by ci.sort_title asc, ci.id asc
order by ca.value_number asc nulls last, ci.sort_title asc, ci.id asc
"""),
{"definition_set_code": definition_set_code},
)

View File

@ -300,6 +300,16 @@ class SeedOrchestrator:
# seeded by this invocation are candidates for module
# association. Never rewrite unrelated template rows.
content_ids = [result.content_id for result in batch.results]
elif batch.results:
# Preserve authored sequence from the source document.
content_ids = [result.content_id for result in batch.results]
known_ids = set(content_ids)
all_ids = await self._modules.resolve_content_ids_for_definition_set(
definition_set_code=mapping.code
)
for remaining_id in all_ids:
if remaining_id not in known_ids:
content_ids.append(remaining_id)
else:
content_ids = await self._modules.resolve_content_ids_for_definition_set(
definition_set_code=mapping.code