Adding some enhancements.
This commit is contained in:
parent
013d1c0bd5
commit
a8b07eb115
4 changed files with 24 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from typing import Type, TypeVar, Generic, Optional
|
||||
from sqlalchemy.orm import Load, Session, raiseload, with_polymorphic
|
||||
from sqlalchemy.orm.attributes import InstrumentedAttribute
|
||||
from sqlalchemy import inspect, text
|
||||
from crudkit.core.base import Version
|
||||
from crudkit.core.spec import CRUDSpec
|
||||
|
|
@ -55,6 +56,7 @@ class CRUDService(Generic[T]):
|
|||
query, root_alias = self.get_query()
|
||||
|
||||
root_fields = []
|
||||
root_field_names = {}
|
||||
rel_field_names = {}
|
||||
|
||||
if params:
|
||||
|
|
@ -77,10 +79,11 @@ class CRUDService(Generic[T]):
|
|||
)
|
||||
|
||||
if params:
|
||||
root_fields, rel_field_names = spec.parse_fields()
|
||||
root_fields, rel_field_names, root_field_names = spec.parse_fields()
|
||||
|
||||
if root_fields:
|
||||
query = query.options(Load(root_alias).load_only(*root_fields))
|
||||
only_cols = [c for c in root_fields if isinstance(c, InstrumentedAttribute)]
|
||||
if only_cols:
|
||||
query = query.options(Load(root_alias).load_only(*only_cols))
|
||||
|
||||
for eager in spec.get_eager_loads(root_alias, fields_map=rel_field_names):
|
||||
query = query.options(eager)
|
||||
|
|
@ -105,6 +108,8 @@ class CRUDService(Generic[T]):
|
|||
rows = query.all()
|
||||
|
||||
proj = []
|
||||
if root_field_names:
|
||||
proj.extend(root_field_names)
|
||||
if root_fields:
|
||||
proj.extend(c.key for c in root_fields)
|
||||
for path, names in (rel_field_names or {}).items():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue