Some additional work done with CRUDKit. May start this over with a better design for CRUDKit.

This commit is contained in:
Yaro Kasear 2025-08-29 16:04:41 -05:00
parent f47fb6b505
commit 7738f1c9c2
5 changed files with 67 additions and 53 deletions

View file

@ -56,7 +56,7 @@ def _apply_dotted_ordering(stmt, Model, sort_tokens):
rel = current_mapper.relationships.get(rel_name)
if rel is None:
# invalid sort key; skip quietly or raise
# raise ValueError(f"Unknown relationship {current_mapper.class_.__name__}.{rel_name}")
print(f"Unknown relationship {current_mapper.class_.__name__}.{rel_name}")
entity = None
break
@ -78,13 +78,20 @@ def _apply_dotted_ordering(stmt, Model, sort_tokens):
continue
col_name = parts[-1]
# Validate final column
if col_name not in current_mapper.columns:
# raise ValueError(f"Unknown column {current_mapper.class_.__name__}.{col_name}")
continue
# # Validate final column
# if col_name not in current_mapper.columns:
# print(f"Unknown column {current_mapper.class_.__name__}.{col_name}")
# continue
col = getattr(entity, col_name) if entity is not Model else getattr(Model, col_name)
stmt = stmt.order_by(col.desc() if direction == "desc" else col.asc())
# col = getattr(entity, col_name) if entity is not Model else getattr(Model, col_name)
attr = getattr(entity, col_name, None)
if attr is None:
attr = getattr(current_mapper.class_, col_name, None)
if attr is None:
print(f"Unknown column {current_mapper.class_.__name__}.{col_name}")
continue
stmt = stmt.order_by(attr.desc() if direction == "desc" else attr.asc())
return stmt