Add filtering for dropdowns.
This commit is contained in:
parent
5234cbdd61
commit
51520da5af
4 changed files with 87 additions and 8 deletions
|
|
@ -415,6 +415,8 @@ class CRUDService(Generic[T]):
|
|||
opt = opt.load_only(*cols)
|
||||
query = query.options(opt)
|
||||
|
||||
# inside CRUDService._apply_firsthop_strategies
|
||||
# ...
|
||||
# NEW: if a first-hop to-one relationship’s target table is present in filter expressions,
|
||||
# make sure we actually JOIN it (outer) so filters don’t create a cartesian product.
|
||||
if plan.filter_tables:
|
||||
|
|
@ -422,14 +424,19 @@ class CRUDService(Generic[T]):
|
|||
for rel in mapper.relationships:
|
||||
if rel.uselist:
|
||||
continue # only first-hop to-one here
|
||||
target_tbl = getattr(rel.mapper.class_, "__table__", None)
|
||||
target_cls = rel.mapper.class_
|
||||
target_tbl = getattr(target_cls, "__table__", None)
|
||||
if target_tbl is None:
|
||||
continue
|
||||
if target_tbl in plan.filter_tables:
|
||||
if rel.key in joined_rel_keys:
|
||||
continue # already joined via join_paths
|
||||
query = query.join(getattr(root_alias, rel.key), isouter=True)
|
||||
|
||||
# alias when joining same-entity relationships (User->User supervisor)
|
||||
ta = aliased(target_cls) if target_cls is self.model else target_cls
|
||||
query = query.join(getattr(root_alias, rel.key).of_type(ta), isouter=True)
|
||||
joined_rel_keys.add(rel.key)
|
||||
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
info = []
|
||||
for base_alias, rel_attr, target_alias in plan.join_paths:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue