Here's some additional example: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('sqlite://', echo=True) Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String(50)) addresses = relation("Address", backref="user") class Address(Base): __tablename__ = 'addresses' id = Column(Integer, primary_key=True) email = Column(String(50)) user_id = Column(Integer, ForeignKey('users.id')) Base.metadata.create_all(engine) session = sessionmaker(bind=engine)() u1 = User(name='ed', addresses=[Address(email='e1'), Address(email='e2')]) for a in u1.addresses: assert a.user is u1 session.add(u1) session.commit() for ad in session.query(Address).filter(Address.user==u1): print ad.email ad1 = session.query(Address).first() print ad1.user.name On Dec 24, 2008, at 5:01 PM, vctr...@gmail.com wrote: > class User(Base): > __tablename__ = 'users' > > id = Column(Integer, primary_key=True) > name = Column(String(50)) > addresses = relation("Address", backref="user") > > class Address(Base): > __tablename__ = 'addresses' > > id = Column(Integer, primary_key=True) > email = Column(String(50)) > user_id = Column(Integer, ForeignKey('users.id')) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---