On Jan 10, 2011, at 1:10 PM, Arturo Sevilla wrote: > Hello, > > I'm trying to do the following: > > 'home': orm.composite( > Address, > user.c.HomeAddress_Street, > # The following column is a UUID but is a foreign key to a > mapped > # table in SQLAlchemy, ideally would be to say > relationship(City) > # and specify the column > user.c.HomeAddress_City, > user.c.HomeAddress_ZipCode > )
I don't understand what this means, i think you're missing some context here that would make this easier for others to understand, are there *other* columns on "user" that also reference "city" ? I don't understand what "relationship() and specify the column" means. relationship() accepts a "primaryjoin" expression for this purpose, its in the docs. If you have "HomeAddress" and "WorkAddress", you'd make two relationships. I also have an intuition, since it seems like you want a variant on relationship(), that composite is definitely not what you want to be using, it pretty much never is, but a picture of all the relevant columns here would be helpful. You definitely cannot use a column that's part of a relationship() in a composite() as well and manipulating foreign keys through composites is not the intended usage. > > As such I tried a simple if isinstance(city, uuid.UUID): city = > City.load(city), where this method is just: > @classmethod > def load(cls, id): > session = Session() > obj = session.query(cls).get(id) > session.close() > return obj > > However during session.commit() it appears that my Session class (made > with scoped_session(sessionmaker()) ) goes to None (and crashes). > Is this an expected behavior? no, the scoped_session object always returns either an existing or a new Session and is never None. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.