So in the ongoing improvement of one of our internal databases, we created
a new table named 'environments' whose SQLA code looks something like
this:

class Environment(Base):
    __tablename__ = 'environments'

    id = Column(u'environmentID', INTEGER(), primary_key=True)
    environment = Column(String(length=15), nullable=False, unique=True)
    env = Column(String(length=12), nullable=False, unique=True)
    domain = Column(String(length=32), nullable=False, unique=True)
    prefix = Column(String(length=1), nullable=False)

Two of our tables recently needed conversion to stop using their own local
'environment' column to using this table.  The first part's been put in
place
(a new foreign key for 'environment_id'), but to prevent large swaths of
code
from needing changes, a thought of using a hybrid property might allow the
change to be hidden (until the code using it had been rewritten at least).

My naive attempt was the following (just the relevant snippet):

    environment_obj = relationship('Environment')

    @hybrid_property
    def environment(self):
        return self.environment_obj.environment

Unfortunately (and in hindsight for obvious reasons), this code doesn't
work,
but a very brief conversation with someone on the #sqlalchemy channel on
Freenode indicated there was no way to do this and all the relevant code
must be reworked.  While it's only a few dozen places this occurs, I can see
this coming up again in the future as further schema refactorings occur, so
I turn to those with more expertise to find out if there is a way to
accomplish
what I desire, or if there's really no hope. :)  Any insight would be
greatly
appreciated.

-- 
- Ken Lareau

-- 
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.

Reply via email to