I noticed that lazy loading on an n:m relation over an intermediate table on an
ancestor gives the wrong results. Atached you find the test-program.

from sqlalchemy import *

engine = create_engine('oracle://dsn=orcl&user=test&password=test')

foo = Table('foo', engine, Column('id', Integer, Sequence('foo_seq'), 
primary_key=True))
bar = Table('bar', engine, Column('id', Integer, ForeignKey('foo.id'), 
primary_key=True))

bar_foo = Table('bar_foo', engine,
    Column('bar_id', Integer, ForeignKey('bar.id')),
    Column('foo_id', Integer, ForeignKey('foo.id'))
    )

class Foo(object): pass
class Bar(object): pass

foos = mapper(Foo, foo)
bars = mapper(Bar, bar, inherits=foos)
bars.add_property('bad', relation(foos, bar_foo, lazy=True))
bars.add_property('good', relation(foos, bar_foo, lazy=False))

tables = foo, bar, bar_foo

for table in reversed(tables):
    try: table.drop()
    except Exception, e: print e

for table in tables:
    try: table.create()
    except Exception, e: print e

foo.insert().execute()
bar.insert().execute(id=1)

foo.insert().execute()
bar.insert().execute(id=2)

foo.insert().execute() #3
foo.insert().execute() #4

bar_foo.insert().execute(bar_id=1, foo_id=3)
bar_foo.insert().execute(bar_id=2, foo_id=4)

print len(bars.selectone().bad) #this is lazy=True and it should not print 2 
but 1
print len(bars.selectone().good)

Reply via email to