support lambdas / strings in column_property

Issue #3050 duplicate
Mike Bayer repo owner created an issue

mostly to support mixins, e.g.

class mymixin(object):
    bar = Column(Integer)
    foo = Column(Integer)

    @declared_attr
    def foo_plus_bar(cls):
        return column_property(lambda: cls.foo + cls.bar)

Comments (6)

  1. Mike Bayer reporter

    also, duh, we need this, this can likely be in 0.9:

    diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py
    index a0def7d..26196c1 100644
    --- a/lib/sqlalchemy/orm/properties.py
    +++ b/lib/sqlalchemy/orm/properties.py
    @@ -148,6 +148,9 @@ class ColumnProperty(StrategizedProperty):
                                         ("instrument", self.instrument)
                                         )
    
    +    def __clause_element__(self):
    +        return self.expression
    +
         @property
         def expression(self):
             """Return the primary column or expression for this ColumnProperty.
    
  2. Log in to comment