summaryrefslogtreecommitdiff
path: root/examples/vertical/vertical.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-07-27 04:08:53 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-07-27 04:08:53 +0000
commited4fc64bb0ac61c27bc4af32962fb129e74a36bf (patch)
treec1cf2fb7b1cafced82a8898e23d2a0bf5ced8526 /examples/vertical/vertical.py
parent3a8e235af64e36b3b711df1f069d32359fe6c967 (diff)
downloadsqlalchemy-ed4fc64bb0ac61c27bc4af32962fb129e74a36bf.tar.gz
merging 0.4 branch to trunk. see CHANGES for details. 0.3 moves to maintenance branch in branches/rel_0_3.
Diffstat (limited to 'examples/vertical/vertical.py')
-rw-r--r--examples/vertical/vertical.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/examples/vertical/vertical.py b/examples/vertical/vertical.py
index e9fff9163..e3b48c336 100644
--- a/examples/vertical/vertical.py
+++ b/examples/vertical/vertical.py
@@ -3,9 +3,12 @@ represented in distinct database rows. This allows objects to be created with d
fields that are all persisted in a normalized fashion."""
from sqlalchemy import *
+from sqlalchemy.orm import *
+from sqlalchemy.orm.collections import mapped_collection
import datetime
-e = MetaData('sqlite://', echo=True)
+e = MetaData('sqlite://')
+e.bind.echo = True
# this table represents Entity objects. each Entity gets a row in this table,
# with a primary key and a title.
@@ -37,14 +40,6 @@ entity_values = Table('entity_values', e,
e.create_all()
-class EntityDict(dict):
- """this is a dictionary that implements an append() and an __iter__ method.
- such a dictionary can be used with SQLAlchemy list-based attributes."""
- def append(self, entityvalue):
- self[entityvalue.field.name] = entityvalue
- def __iter__(self):
- return iter(self.values())
-
class Entity(object):
"""represents an Entity. The __getattr__ method is overridden to search the
object's _entities dictionary for the appropriate value, and the __setattribute__
@@ -123,7 +118,7 @@ mapper(
)
mapper(Entity, entities, properties = {
- '_entities' : relation(EntityValue, lazy=False, cascade='all', collection_class=EntityDict)
+ '_entities' : relation(EntityValue, lazy=False, cascade='all', collection_class=mapped_collection(lambda entityvalue: entityvalue.field.name))
})
# create two entities. the objects can be used about as regularly as