Skip to content

Commit 1df9e1a

Browse files
committed
Make 'find' work for rev_multilink properties
1 parent 7db1265 commit 1df9e1a

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

roundup/backends/back_anydbm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,7 @@ def find(self, **propspec):
15811581
# ok, now do the find
15821582
cldb = self.db.getclassdb(self.classname)
15831583
l = []
1584+
rev_multilinks = []
15841585
try:
15851586
for id in self.getnodeids(db=cldb):
15861587
item = self.db.getnode(self.classname, id, db=cldb)
@@ -1607,6 +1608,9 @@ def find(self, **propspec):
16071608
l.append(id)
16081609
break
16091610
elif isinstance(prop, hyperdb.Multilink):
1611+
if prop.rev_property:
1612+
rev_multilinks.append ((prop, itemids))
1613+
continue
16101614
hit = 0
16111615
for v in value:
16121616
if v in itemids:
@@ -1615,6 +1619,15 @@ def find(self, **propspec):
16151619
break
16161620
if hit:
16171621
break
1622+
for prop, itemids in rev_multilinks:
1623+
rprop = prop.rev_property
1624+
fun = l.append
1625+
if isinstance (rprop, hyperdb.Multilink):
1626+
fun = l.extend
1627+
for id in itemids:
1628+
fun(rprop.cls.get(id, rprop.name))
1629+
if rev_multilinks:
1630+
l = list(sorted(set(l)))
16181631
finally:
16191632
cldb.close()
16201633
return l

roundup/backends/rdbms_common.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,21 +2252,29 @@ def find(self, **propspec):
22522252

22532253
# now multilinks
22542254
for prop, values in propspec.items():
2255-
if not isinstance(props[prop], hyperdb.Multilink):
2255+
p = props[prop]
2256+
if not isinstance(p, hyperdb.Multilink):
22562257
continue
22572258
if not values:
22582259
continue
22592260
allvalues += (0, )
2261+
tn = p.table_name
2262+
ln = p.linkid_name
2263+
nn = p.nodeid_name
2264+
cn = '_' + self.classname
2265+
ret = ''
2266+
if p.rev_property and isinstance(p.rev_property, Link):
2267+
ret = 'and %s.__retired__=%s ' % (tn, a)
2268+
allvalues += (0, )
22602269
if type(values) is type(''):
22612270
allvalues += (values,)
22622271
s = a
22632272
else:
22642273
allvalues += tuple(values)
22652274
s = ','.join([a]*len(values))
2266-
tn = '%s_%s'%(self.classname, prop)
2267-
sql.append("""select id from _%s, %s where __retired__=%s
2268-
and id = %s.nodeid and %s.linkid in (%s)"""%(self.classname,
2269-
tn, a, tn, tn, s))
2275+
sql.append("""select %s.id from %s, %s where %s.__retired__=%s
2276+
%sand %s.id = %s.%s and %s.%s in (%s)"""%(cn, cn, tn, cn,
2277+
a, ret, cn, tn, nn, tn, ln, s))
22702278

22712279
if not sql:
22722280
return []

test/db_test_base.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,33 @@ def testFindLink(self):
15641564
got.sort()
15651565
self.assertEqual(got, [one, three])
15661566

1567+
def testFindRevLinkMultilink(self):
1568+
ae, filter, filter_iter = self.filteringSetupTransitiveSearch('user')
1569+
ni = 'nosy_issues'
1570+
self.db.issue.set('6', nosy=['3', '4', '5'])
1571+
self.db.issue.set('7', nosy=['5'])
1572+
# After this setup we have the following values for nosy:
1573+
# issue assignedto nosy
1574+
# 1: 6 4
1575+
# 2: 6 5
1576+
# 3: 7
1577+
# 4: 8
1578+
# 5: 9
1579+
# 6: 10 3, 4, 5
1580+
# 7: 10 5
1581+
# 8: 10
1582+
# assignedto links back from 'issues'
1583+
# nosy links back from 'nosy_issues'
1584+
self.assertEqual(self.db.user.find(issues={'1':1}), ['6'])
1585+
self.assertEqual(self.db.user.find(issues={'8':1}), ['10'])
1586+
self.assertEqual(self.db.user.find(issues={'2':1, '5':1}), ['6', '9'])
1587+
self.assertEqual(self.db.user.find(nosy_issues={'8':1}), [])
1588+
self.assertEqual(self.db.user.find(nosy_issues={'6':1}),
1589+
['3', '4', '5'])
1590+
self.assertEqual(self.db.user.find(nosy_issues={'3':1, '5':1}), [])
1591+
self.assertEqual(self.db.user.find(nosy_issues={'2':1, '6':1, '7':1}),
1592+
['3', '4', '5'])
1593+
15671594
def testFindLinkFail(self):
15681595
self._find_test_setup()
15691596
self.assertEqual(self.db.issue.find(status='4'), [])

0 commit comments

Comments
 (0)