Just noticed that SQLAlchemy 0.9 broke a LazyForeignKey class that was
provided by TurboGears tgext.pluggable to make possible to declare foreign
keys to models not yet defined at the time the ForeignKey was declared.

The main use was something like:

class User(DeclarativeBase):
    __tablename__ = 'users'

    registration_id = Column(Integer, LazyForeignKey(lambda:
app_model.Registration.uid))

where app_model.Registration was available only at runtime and not when
User class was declared.
Also app_model.Registration table name was not known (as it dynamically
generated to avoid collision between tables of multiple apps plugged at
runtime), so it was not possible to declare the foreign key as a string
with the "tablename.column_name" syntax.

LazyForeignKey was simply implemented as a subclass of ForeignKey which
provided a custom _colspec property which would resolve the given function
whenever it was first accessed:
https://github.com/TurboGears/tgext.pluggable/blob/master/tgext/pluggable/sqla/relations.py#L4

This approach doesn't work anymore in SQLA 0.9 as _colspec gets accessed by
the ForeignKey constructor itself, calling the lambda at Column declaration
time.

It seems to me that adapting the LazyForeignKey class to SQLA 0.9 would
require messing a lot more with SQLAlchemy internal code, which is
something I would like to avoid.

What would be the suggested way to achieve the same feature on SQLA 0.9?

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to