diff options
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 10 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/util.py | 11 |
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 9508cb532..a00d4078a 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -276,6 +276,7 @@ class Query(object): return self._select_from_entity or \ self._entity_zero().entity_zero + @property def _mapper_entities(self): # TODO: this is wrong, its hardcoded to "primary entity" when @@ -3086,8 +3087,9 @@ class _MapperEntity(_QueryEntity): class _ColumnEntity(_QueryEntity): """Column/expression based entity.""" - def __init__(self, query, column): + def __init__(self, query, column, namespace=None): self.expr = column + self.namespace = namespace if isinstance(column, basestring): column = sql.literal_column(column) @@ -3106,7 +3108,7 @@ class _ColumnEntity(_QueryEntity): for c in column._select_iterable: if c is column: break - _ColumnEntity(query, c) + _ColumnEntity(query, c, namespace=column) if c is not column: return @@ -3147,12 +3149,14 @@ class _ColumnEntity(_QueryEntity): if self.entities: self.entity_zero = list(self.entities)[0] + elif self.namespace is not None: + self.entity_zero = self.namespace else: self.entity_zero = None @property def entity_zero_or_selectable(self): - if self.entity_zero: + if self.entity_zero is not None: return self.entity_zero elif self.actual_froms: return list(self.actual_froms)[0] diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 0cd5b0594..6ac03d95a 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -557,15 +557,20 @@ def _entity_descriptor(entity, key): attribute. """ - if not isinstance(entity, (AliasedClass, type)): - entity = entity.class_ + if isinstance(entity, expression.FromClause): + description = entity + entity = entity.c + elif not isinstance(entity, (AliasedClass, type)): + description = entity = entity.class_ + else: + description = entity try: return getattr(entity, key) except AttributeError: raise sa_exc.InvalidRequestError( "Entity '%s' has no property '%s'" % - (entity, key) + (description, key) ) def _orm_columns(entity): |
