):
"""Load columns for inheriting classes.
+ This is a legacy method which is replaced by the
+ :func:`_orm.with_polymorphic` function.
+
+ .. warning:: The :meth:`_orm.Query.with_polymorphic` method does
+ **not** support 1.4/2.0 style features including
+ :func:`_orm.with_loader_criteria`. Please migrate code
+ to use :func:`_orm.with_polymorphic`.
+
:meth:`_query.Query.with_polymorphic` applies transformations
to the "main" mapped class represented by this :class:`_query.Query`.
The "main" mapped class here means the :class:`_query.Query`
purposes of load-time efficiency as well as the ability to use
these columns at query time.
- See the documentation section :ref:`with_polymorphic` for
- details on how this method is used.
+ .. seealso::
+
+ :ref:`with_polymorphic` - illustrates current patterns
"""
# if options to limit the criteria to immediate query only,
# use compile_state.attributes instead
+ if compile_state.compile_options._with_polymorphic_adapt_map:
+ util.warn(
+ "The with_loader_criteria() function may not work "
+ "correctly with the legacy Query.with_polymorphic() feature. "
+ "Please migrate code to use the with_polymorphic() standalone "
+ "function before using with_loader_criteria()."
+ )
if not compile_state.compile_options._for_refresh_state:
self.get_global_criteria(compile_state.global_attributes)
from sqlalchemy.orm import subqueryload
from sqlalchemy.orm import synonym
from sqlalchemy.orm import undefer
+from sqlalchemy.orm import with_loader_criteria
from sqlalchemy.orm import with_parent
from sqlalchemy.orm import with_polymorphic
from sqlalchemy.orm.collections import collection
use_default_dialect=True,
)
+ def test_with_poly_loader_criteria_warning(self):
+ Person, Manager = (
+ self.classes.Person,
+ self.classes.Manager,
+ )
+
+ sess = fixture_session()
+
+ with testing.expect_deprecated_20(w_polymorphic_dep):
+ q = (
+ sess.query(Person)
+ .with_polymorphic(Manager)
+ .options(with_loader_criteria(Person, Person.person_id == 1))
+ )
+
+ with testing.expect_warnings(
+ r"The with_loader_criteria\(\) function may not work "
+ r"correctly with the legacy Query.with_polymorphic\(\)"
+ ):
+ str(q)
+
class JoinFromSelectableTest(fixtures.MappedTest, AssertsCompiledSQL):
__dialect__ = "default"