8 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Overriding table col...| From | Sent On | Attachments |
|---|---|---|
| Malthe Borch | 18 Jul 2008 11:23 | |
| Michael Bayer | 18 Jul 2008 12:03 | |
| Malthe Borch | 19 Jul 2008 04:39 | |
| Michael Bayer | 20 Jul 2008 10:32 | |
| Michael Bayer | 20 Jul 2008 11:36 | |
| Malthe Borch | 20 Jul 2008 14:50 | |
| Malthe Borch | 22 Jul 2008 00:40 | |
| Malthe Borch | 22 Jul 2008 04:27 |
| Subject: | [sqlalchemy] Re: Overriding table columns with Python-property![]() |
|---|---|
| From: | Malthe Borch (mbo...@gmail.com) |
| Date: | 07/19/2008 04:39:14 AM |
| List: | com.googlegroups.sqlalchemy |
Michael Bayer wrote:
works for me:
I tried adapting your example, which admittedly works :-), to a scenario that better resembles mine, but now the property is overriden simply, even when I use ``exclude_properties``.
Note that the setup is overly complex, but this should be seen in the light of a larger setup (as you've previously guided me towards, incidentally).
from sqlalchemy import * from sqlalchemy.orm import *
e = create_engine('sqlite://') m = MetaData(e)
t1= Table( 't1', m, Column('id', Integer, primary_key=True), Column('col', String(50)), ) t1.create()
t2= Table( 't2', m, Column('id', Integer, ForeignKey("t1.id"), primary_key=True), Column('data', String(50)), ) t2.create()
class T1(object): pass
class T2(T1): @property def col(self): return u"Some read-only value."
polymorphic = ( [T2], t1.join(t2))
mapper(T1, t1) mapper( T2, t2, exclude_properties=('col',), with_polymorphic=polymorphic, inherits=T1, inherit_condition=(t1.c.id==t2.c.id), )
sess = sessionmaker()() x = T2()
assert type(T2.col) is property
x.data = "some data" sess.save(x) sess.commit() sess.clear()
assert sess.query(T2).one().data == "some data" assert sess.query(T2).one().col == u"Some read-only value."
x = sess.query(T2).one() x.data = "some new data" sess.commit() assert sess.query(T2).one().data == "some new data"
\malthe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqla...@googlegroups.com
To unsubscribe from this group, send email to
sqla...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---




