add parameter usePredicateIndex to getRelations()
This commit is contained in:
parent
bd1aa11beb
commit
1629defe3d
1 changed files with 17 additions and 14 deletions
|
@ -227,7 +227,8 @@ class IndexableRelationAdapter(object):
|
||||||
|
|
||||||
# convenience functions:
|
# convenience functions:
|
||||||
|
|
||||||
def getRelations(first=None, second=None, third=None, relationships=None):
|
def getRelations(first=None, second=None, third=None, relationships=None,
|
||||||
|
usePredicateIndex=False):
|
||||||
""" Return a sequence of relations matching the query specified by the
|
""" Return a sequence of relations matching the query specified by the
|
||||||
parameters.
|
parameters.
|
||||||
|
|
||||||
|
@ -241,19 +242,21 @@ def getRelations(first=None, second=None, third=None, relationships=None):
|
||||||
if third is not None: query['third'] = third
|
if third is not None: query['third'] = third
|
||||||
if not relationships:
|
if not relationships:
|
||||||
return registry.query(**query)
|
return registry.query(**query)
|
||||||
else:
|
if len(relationships) == 1 and usePredicateIndex:
|
||||||
predicates = []
|
query['relationship'] = relationships[0]
|
||||||
for r in relationships:
|
return registry.query(**query)
|
||||||
if hasattr(r, 'predicate'):
|
predicates = []
|
||||||
predicates.append(r.predicate)
|
for r in relationships:
|
||||||
r.predicate = None
|
if hasattr(r, 'predicate'):
|
||||||
else:
|
predicates.append(r.predicate)
|
||||||
predicates.append(r.getPredicateName())
|
r.predicate = None
|
||||||
result = registry.query(**query)
|
else:
|
||||||
if predicates:
|
predicates.append(r.getPredicateName())
|
||||||
return [r for r in result
|
result = registry.query(**query)
|
||||||
if r.ident in predicates or r.fallback in predicates]
|
if predicates:
|
||||||
return result
|
return [r for r in result
|
||||||
|
if r.ident in predicates or r.fallback in predicates]
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def getRelationSingle(obj=None, relationship=None, forSecond=True):
|
def getRelationSingle(obj=None, relationship=None, forSecond=True):
|
||||||
|
|
Loading…
Add table
Reference in a new issue