raise sa_exc.ArgumentError(
"adapt_on_names only applies to ORM elements"
)
- return coercions.expect(
- roles.AnonymizedFromClauseRole, element, name=name, flat=flat
- )
+ if name:
+ return element.alias(name=name, flat=flat)
+ else:
+ return coercions.expect(
+ roles.AnonymizedFromClauseRole, element, flat=flat
+ )
else:
return AliasedClass(
element,
from sqlalchemy import inspect
from sqlalchemy import Integer
from sqlalchemy import MetaData
+from sqlalchemy import select
from sqlalchemy import Table
from sqlalchemy import util
from sqlalchemy.ext.hybrid import hybrid_method
assert Point.id.__clause_element__().table is table
assert alias.id.__clause_element__().table is not table
+ def test_named_entity(self):
+ class Point(object):
+ pass
+
+ self._fixture(Point)
+
+ alias = aliased(Point, name="pp")
+
+ self.assert_compile(
+ select(alias), "SELECT pp.id, pp.x, pp.y FROM point AS pp"
+ )
+
+ def test_named_selectable(self):
+ class Point(object):
+ pass
+
+ table = self._fixture(Point)
+
+ alias = aliased(table, name="pp")
+
+ self.assert_compile(
+ select(alias), "SELECT pp.id, pp.x, pp.y FROM point AS pp"
+ )
+
def test_not_instantiatable(self):
class Point(object):
pass