Hello, I am trying to do something odd, but I was wondering if this
could be done with SQLAlchemy. See the script for details:
from sqlalchemy import *
metadata = BoundMetaData('sqlite://')
class Item(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return '<%s:%s>' % (self.__class__.__name__, self.name)
item_table = Table('item', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(50)))
collection_table = Table('collection', metadata,
Column('id_coll', Integer, ForeignKey("item.id"), nullable=False),
Column('id_item', Integer, ForeignKey("item.id"), nullable=False))
item_mapper = mapper(Item, item_table, properties=dict(
collections=relation(Item, secondary=collection_table ,lazy=True,
backref='items')))
metadata.create_all()
session = create_session()
session.save(Item('Koen Bok'))
session.save(Item('Dirk Stoop'))
session.flush()
# And now we should be able to do something like this:
items = session.query(Item).select()
for item in items:
for i in items:
item.items.append(i)
item.collections.append(i)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---