Refactored condition property
This commit is contained in:
@@ -292,11 +292,15 @@ class Fetcher(object):
|
|||||||
if self.path.populate_backrefs:
|
if self.path.populate_backrefs:
|
||||||
self.populate_backrefs(self.related_entities)
|
self.populate_backrefs(self.related_entities)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def remote(self):
|
||||||
|
return self.path.model
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def condition(self):
|
def condition(self):
|
||||||
names = self.remote_column_names
|
names = self.remote_column_names
|
||||||
if len(names) == 1:
|
if len(names) == 1:
|
||||||
return getattr(self.path.model, names[0]).in_(
|
return getattr(self.remote, names[0]).in_(
|
||||||
value[0] for value in self.local_values_list
|
value[0] for value in self.local_values_list
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -305,10 +309,11 @@ class Fetcher(object):
|
|||||||
conditions.append(
|
conditions.append(
|
||||||
sa.and_(
|
sa.and_(
|
||||||
*[
|
*[
|
||||||
getattr(self.path.model, remote.name)
|
getattr(self.remote, remote.name)
|
||||||
==
|
==
|
||||||
getattr(entity, local.name)
|
getattr(entity, local.name)
|
||||||
for local, remote in self.prop.local_remote_pairs
|
for local, remote in self.prop.local_remote_pairs
|
||||||
|
if remote in self.remote_column_names
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -320,6 +325,10 @@ class Fetcher(object):
|
|||||||
|
|
||||||
|
|
||||||
class ManyToManyFetcher(Fetcher):
|
class ManyToManyFetcher(Fetcher):
|
||||||
|
@property
|
||||||
|
def remote(self):
|
||||||
|
return self.prop.secondary.c
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def remote_column_names(self):
|
def remote_column_names(self):
|
||||||
names = []
|
names = []
|
||||||
@@ -331,31 +340,6 @@ class ManyToManyFetcher(Fetcher):
|
|||||||
|
|
||||||
return names
|
return names
|
||||||
|
|
||||||
@property
|
|
||||||
def condition(self):
|
|
||||||
if len(self.remote_column_names) == 1:
|
|
||||||
return (
|
|
||||||
getattr(self.prop.secondary.c, self.remote_column_names[0])
|
|
||||||
.in_(
|
|
||||||
[value[0] for value in self.local_values_list]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
conditions = []
|
|
||||||
for entity in self.path.entities:
|
|
||||||
conditions.append(
|
|
||||||
sa.and_(
|
|
||||||
*[
|
|
||||||
getattr(self.prop.secondary.c, remote.name)
|
|
||||||
==
|
|
||||||
getattr(entity, local.name)
|
|
||||||
for local, remote in self.prop.local_remote_pairs
|
|
||||||
if remote.name in self.remote_column_names
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return sa.or_(*conditions)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def related_entities(self):
|
def related_entities(self):
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user