When accessing a relation over a mapper, then updating a value in a row of the
related table (not with the mapper) and then accessing again relation, the
value is not updated.
Maybe that is expected behavior, I find it strange however. See the code below.
I also saw that for the second access to the foo property no sql query was
generated. So seemingly the Foo instance was cached somewhere.
See the example atached.
Cheers,
Florian
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),
Column('title', Unicode(255)))
bar = Table('bar', engine,
Column('id', Integer, Sequence('bar_seq'), primary_key=True),
Column('foo_id', Integer, ForeignKey('foo.id')))
all = bar, foo
for table in all:
try: table.drop()
except Exception, e: print e
for table in reversed(all):
try: table.create()
except Exception, e: print e
class Foo(object): pass
foos = mapper(Foo, foo)
class Bar(object): pass
bars = mapper(Bar, bar)
bars.add_property('foo', relation(foos))
foo.insert().execute(title='asfd')
bar.insert().execute(foo_id=1)
bars.selectfirst().foo
foo.update(foo.c.id==1).execute(title='sometitle')
assert bars.selectfirst().foo.title == 'sometitle' #this fails, uh?