On Thursday, June 26, 2014 10:38:50 AM UTC-4, Victor Olex wrote: > > I read it, but could you illustrate it with a sample code based on the > classic User/Addresses example? > >>
This is some pseudocode just to get the point across. I use 2 files, one for the base class, the other for the "user" class. The base class defines the objects, the other class "extends" them In practice, I build up the registry dynamically by inspecting all the items in the user library to see if they inherit from `_CoreObject`, then figuring out which object they implement ## # your core library ## class _CoreObject(object): pass class _User(_CoreObject): id = Column(Integer, Sequence('user_id_seq'), primary_key=True) name = Column(String(50)) fullname = Column(String(50)) password = Column(String(12)) class _Address(_CoreObject): id = Column(Integer, primary_key=True) email_address = Column(String, nullable=False) user_id = Column(Integer, ForeignKey('users.id')) def setup_relationships( registry ): registry['Address'].user = relationship(registry['User'], backref=backref('addresses', order_by=registry['Address'].id)) ## # user library ## class User(_User, Base): __tablename__ = 'users' class Address(_Address, Base): __tablename__ = 'addresses' registry = { 'User' : User, 'Address' : Address, } setup_relationships(registry) -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.