Fixed issue in new :meth:`_schema.Table.table_valued` method where the
resulting :class:`_sql.TableValuedColumn` construct would not respond
correctly to alias adaptation as is used throughout the ORM, such as for
eager loading, polymorphic loading, etc.
Fixes: #6775
Change-Id: I77cec4b6e1b1003f2b6be242b54ada8e4a435250
--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 6775
+
+ Fixed issue in new :meth:`_schema.Table.table_valued` method where the
+ resulting :class:`_sql.TableValuedColumn` construct would not respond
+ correctly to alias adaptation as is used throughout the ORM, such as for
+ eager loading, polymorphic loading, etc.
+
self.key = self.name = scalar_alias.name
self.type = type_
+ def _copy_internals(self, clone=_clone, **kw):
+ self.scalar_alias = clone(self.scalar_alias, **kw)
+ self.key = self.name = self.scalar_alias.name
+
@property
def _from_objects(self):
return [self.scalar_alias]
"FROM table1 AS table1_1",
)
+ def test_table_valued_column(self):
+ """test #6775"""
+ stmt = select(func.some_json_func(t1.table_valued()))
+
+ self.assert_compile(
+ stmt,
+ "SELECT some_json_func(table1) AS some_json_func_1 FROM table1",
+ )
+
+ self.assert_compile(
+ sql_util.ClauseAdapter(t1.alias()).traverse(stmt),
+ "SELECT some_json_func(table1_1) AS some_json_func_1 "
+ "FROM table1 AS table1_1",
+ )
+
def test_recursive(self):
metadata = MetaData()
a = Table("a", metadata, Column("id", Integer, primary_key=True))