add parameter usePredicateIndex to getRelations()

This commit is contained in:
zope 2021-08-07 11:44:01 +02:00
parent bd1aa11beb
commit 1629defe3d

View file

@ -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,7 +242,9 @@ 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:
query['relationship'] = relationships[0]
return registry.query(**query)
predicates = [] predicates = []
for r in relationships: for r in relationships:
if hasattr(r, 'predicate'): if hasattr(r, 'predicate'):