support lambdas / strings in column_property
Issue #3050
duplicate
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)
-
reporter -
reporter - edited description
-
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.
-
reporter just created
#3066for that second part -
reporter -
reporter - changed status to duplicate
Duplicate of
#3150. - Log in to comment
this also needs docs. the docs at http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative.html#mixing-in-deferred-column-property-and-other-mapperproperty-classes are totally useless here - the lambda: approach is needed for any column_property used in a mixin since the real columns are not available yet.