Drop batch fetch related utilities
This commit is contained in:
@@ -390,71 +390,6 @@ def getattrs(obj, attrs):
|
||||
return map(partial(getattr, obj), attrs)
|
||||
|
||||
|
||||
def local_values(prop, entity):
|
||||
return tuple(getattrs(entity, local_column_names(prop)))
|
||||
|
||||
|
||||
def list_local_values(prop, entities):
|
||||
return map(partial(local_values, prop), entities)
|
||||
|
||||
|
||||
def remote_values(prop, entity):
|
||||
return tuple(getattrs(entity, remote_column_names(prop)))
|
||||
|
||||
|
||||
def local_remote_expr(prop, entity):
|
||||
return sa.and_(
|
||||
*[
|
||||
getattr(remote(prop), r.name)
|
||||
==
|
||||
getattr(entity, l.name)
|
||||
for l, r in prop.local_remote_pairs
|
||||
if r in remote_column_names(prop)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def list_local_remote_exprs(prop, entities):
|
||||
return map(partial(local_remote_expr, prop), entities)
|
||||
|
||||
|
||||
def remote(prop):
|
||||
try:
|
||||
return prop.secondary.c
|
||||
except AttributeError:
|
||||
return prop.mapper.class_
|
||||
|
||||
|
||||
def local_column_names(prop):
|
||||
if not hasattr(prop, 'secondary'):
|
||||
yield prop._discriminator_col.key
|
||||
for id_col in prop._id_cols:
|
||||
yield id_col.key
|
||||
elif prop.secondary is None:
|
||||
for local, _ in prop.local_remote_pairs:
|
||||
yield local.name
|
||||
else:
|
||||
if prop.secondary is not None:
|
||||
for local, remote in prop.local_remote_pairs:
|
||||
for fk in remote.foreign_keys:
|
||||
if fk.column.table in prop.parent.tables:
|
||||
yield local.name
|
||||
|
||||
|
||||
def remote_column_names(prop):
|
||||
if not hasattr(prop, 'secondary'):
|
||||
yield '__tablename__'
|
||||
yield 'id'
|
||||
elif prop.secondary is None:
|
||||
for _, remote in prop.local_remote_pairs:
|
||||
yield remote.name
|
||||
else:
|
||||
for _, remote in prop.local_remote_pairs:
|
||||
for fk in remote.foreign_keys:
|
||||
if fk.column.table in prop.parent.tables:
|
||||
yield remote.name
|
||||
|
||||
|
||||
def quote(mixed, ident):
|
||||
"""
|
||||
Conditionally quote an identifier.
|
||||
|
Reference in New Issue
Block a user