summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/ext/associationproxy.py19
-rw-r--r--lib/sqlalchemy/orm/mapper.py10
-rw-r--r--lib/sqlalchemy/orm/strategy_options.py3
-rw-r--r--lib/sqlalchemy/testing/warnings.py8
4 files changed, 26 insertions, 14 deletions
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py
index 411033a6b..dd5c10ac9 100644
--- a/lib/sqlalchemy/ext/associationproxy.py
+++ b/lib/sqlalchemy/ext/associationproxy.py
@@ -472,10 +472,23 @@ class AssociationProxyInstance(object):
def attr(self):
"""Return a tuple of ``(local_attr, remote_attr)``.
- This attribute is convenient when specifying a join
- using :meth:`_query.Query.join` across two relationships::
+ This attribute was originally intended to facilitate using the
+ :meth:`_query.Query.join` method to join across the two relationships
+ at once, however this makes use of a deprecated calling style.
+
+ To use :meth:`_sql.select.join` or :meth:`_orm.Query.join` with
+ an association proxy, the current method is to make use of the
+ :attr:`.AssociationProxyInstance.local_attr` and
+ :attr:`.AssociationProxyInstance.remote_attr` attributes separately::
+
+ stmt = (
+ select(Parent).
+ join(Parent.proxied.local_attr).
+ join(Parent.proxied.remote_attr)
+ )
- sess.query(Parent).join(*Parent.proxied.attr)
+ A future release may seek to provide a more succinct join pattern
+ for association proxy attributes.
.. seealso::
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index 1aa6666a5..4de12b88c 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -3111,14 +3111,20 @@ class Mapper(
# "enable" options, to turn on the properties that we want to
# load by default (subject to options from the query)
enable_opt.set_generic_strategy(
- (prop.key,), dict(prop.strategy_key)
+ # convert string name to an attribute before passing
+ # to loader strategy
+ (getattr(entity.entity_namespace, prop.key),),
+ dict(prop.strategy_key),
)
else:
# "disable" options, to turn off the properties from the
# superclass that we *don't* want to load, applied after
# the options from the query to override them
disable_opt.set_generic_strategy(
- (prop.key,), {"do_nothing": True}
+ # convert string name to an attribute before passing
+ # to loader strategy
+ (getattr(entity.entity_namespace, prop.key),),
+ {"do_nothing": True},
)
primary_key = [
diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py
index b7ed4e89b..675c7218b 100644
--- a/lib/sqlalchemy/orm/strategy_options.py
+++ b/lib/sqlalchemy/orm/strategy_options.py
@@ -301,6 +301,7 @@ class Load(Generative, LoaderOption):
)
if isinstance(attr, util.string_types):
+
default_token = attr.endswith(_DEFAULT_TOKEN)
attr_str_name = attr
if attr.endswith(_WILDCARD_TOKEN) or default_token:
@@ -328,7 +329,7 @@ class Load(Generative, LoaderOption):
"Using strings to indicate column or "
"relationship paths in loader options is deprecated "
"and will be removed in SQLAlchemy 2.0. Please use "
- "the class-bound attribute directly."
+ "the class-bound attribute directly.",
)
try:
# use getattr on the class to work around
diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py
index 9e02a0c03..9886b122d 100644
--- a/lib/sqlalchemy/testing/warnings.py
+++ b/lib/sqlalchemy/testing/warnings.py
@@ -73,16 +73,8 @@ def setup_filters():
r"The Query\.with_parent\(\) method",
r"The Query\.select_entity_from\(\) method",
r"The ``aliased`` and ``from_joinpoint`` keyword arguments",
- r"Using strings to indicate relationship names in Query.join",
- r"Using strings to indicate column or relationship paths in "
- "loader options",
- r"Using strings to indicate relationship names in the ORM "
- r"with_parent\(\)",
r"The Query.with_polymorphic\(\) method is considered "
"legacy as of the 1.x series",
- r"Passing a chain of multiple join conditions to Query.join\(\) "
- r"is deprecated and will be removed in SQLAlchemy 2.0.",
- r"Query.join\(\) will no longer accept tuples as arguments",
#
# ORM Session
#