.. change::
:tags: bug, orm
- :tickets: 10365
+ :tickets: 10365, 11412
Fixed bug where ORM :func:`_orm.with_loader_criteria` would not apply
itself to a :meth:`_sql.Select.join` where the ON clause were given as a
This is a backport of the same issue fixed in version 2.0 for 2.0.22.
+ **update** - this was found to also fix an issue where
+ single-inheritance criteria would not be correctly applied to a
+ subclass entity that only appeared in the ``select_from()`` list,
+ see :ticket:`11412`
+
.. changelog::
:version: 1.4.51
:released: January 2, 2024
"WHERE employees_1.type IN (__[POSTCOMPILE_type_1])",
)
+ @testing.combinations(
+ (
+ lambda Engineer, Report: select(Report.report_id)
+ .select_from(Engineer)
+ .join(Engineer.reports),
+ ),
+ (
+ lambda Engineer, Report: select(Report.report_id).select_from(
+ orm_join(Engineer, Report, Engineer.reports)
+ ),
+ ),
+ (
+ lambda Engineer, Report: select(Report.report_id).join_from(
+ Engineer, Report, Engineer.reports
+ ),
+ ),
+ (
+ lambda Engineer, Report: select(Report.report_id)
+ .select_from(Engineer)
+ .join(Report),
+ ),
+ argnames="stmt_fn",
+ )
+ @testing.combinations(True, False, argnames="alias_engineer")
+ def test_select_col_only_from_w_join(self, stmt_fn, alias_engineer):
+ """test #11412 which seems to have been fixed by #10365"""
+
+ Engineer = self.classes.Engineer
+ Report = self.classes.Report
+
+ if alias_engineer:
+ Engineer = aliased(Engineer)
+ stmt = testing.resolve_lambda(
+ stmt_fn, Engineer=Engineer, Report=Report
+ )
+
+ if alias_engineer:
+ self.assert_compile(
+ stmt,
+ "SELECT reports.report_id FROM employees AS employees_1 "
+ "JOIN reports ON employees_1.employee_id = "
+ "reports.employee_id WHERE employees_1.type "
+ "IN (__[POSTCOMPILE_type_1])",
+ )
+ else:
+ self.assert_compile(
+ stmt,
+ "SELECT reports.report_id FROM employees JOIN reports "
+ "ON employees.employee_id = reports.employee_id "
+ "WHERE employees.type IN (__[POSTCOMPILE_type_1])",
+ )
+
@testing.combinations(
(
lambda Engineer, Report: select(Report)