]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add cross-linking for self-referential examples
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 23 Apr 2021 15:29:58 +0000 (11:29 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 23 Apr 2021 15:29:58 +0000 (11:29 -0400)
Change-Id: Ib2cb88210c680baafc26f714263309af11cda15a
References: #6351

doc/build/orm/join_conditions.rst
doc/build/orm/self_referential.rst

index 9f163307e4fe13105aed21896701580409a9dec5..21fa5e73100a9557ad8db8ee3ce014d45cd9249b 100644 (file)
@@ -522,6 +522,14 @@ we seek for a load of ``Element.descendants`` to look like::
 Self-Referential Many-to-Many Relationship
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+.. seealso::
+
+    This section documents a two-table variant of the "adjacency list" pattern,
+    which is documented at :ref:`self_referential`.  Be sure to review the
+    self-referential querying patterns in subsections
+    :ref:`self_referential_query` and :ref:`self_referential_eager_loading`
+    which apply equally well to the mapping pattern discussed here.
+
 Many to many relationships can be customized by one or both of :paramref:`_orm.relationship.primaryjoin`
 and :paramref:`_orm.relationship.secondaryjoin` - the latter is significant for a relationship that
 specifies a many-to-many reference using the :paramref:`_orm.relationship.secondary` argument.
@@ -620,6 +628,14 @@ direction, it's smart enough to reverse the
 :paramref:`_orm.relationship.primaryjoin` and
 :paramref:`_orm.relationship.secondaryjoin` arguments.
 
+.. seealso::
+
+  * :ref:`self_referential` - single table version
+  * :ref:`self_referential_query` - tips on querying with self-referential
+    mappings
+  * :ref:`self_referential_eager_loading` - tips on eager loading with self-
+    referential mapping
+
 .. _composite_secondary_join:
 
 Composite "Secondary" Joins
index 739b6e06877ef5fe53e709224d2cba95f475fe36..e931c783cb38bd383cac243c92e7f24cfea1f675 100644 (file)
@@ -14,6 +14,13 @@ storage needs, for reasons of concurrency, reduced complexity, and that
 modified preorder has little advantage over an application which can fully
 load subtrees into the application space.
 
+.. seealso::
+
+    This section details the single-table version of a self-referential
+    relationship. For a self-referential relationship that uses a second table
+    as an association table, see the section
+    :ref:`self_referential_many_to_many`.
+
 In this example, we'll work with a single mapped
 class called ``Node``, representing a tree structure::
 
@@ -114,6 +121,8 @@ is on both sides, and aligns the "remote" column along with the
 ``folder_id`` column, which it recognizes as uniquely present on
 the "remote" side.
 
+.. _self_referential_query:
+
 Self-Referential Query Strategies
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -137,11 +146,11 @@ looks like:
     from sqlalchemy.orm import aliased
 
     nodealias = aliased(Node)
-    {sql}session.query(Node).filter(Node.data=='subchild1').\
+    session.query(Node).filter(Node.data=='subchild1').\
                     join(Node.parent.of_type(nodealias)).\
                     filter(nodealias.data=="child2").\
                     all()
-    SELECT node.id AS node_id,
+    {opensql}SELECT node.id AS node_id,
             node.parent_id AS node_parent_id,
             node.data AS node_data
     FROM node JOIN node AS node_1
@@ -180,8 +189,8 @@ configured via :paramref:`~.relationships.join_depth`:
                         lazy="joined",
                         join_depth=2)
 
-    {sql}session.query(Node).all()
-    SELECT node_1.id AS node_1_id,
+    session.query(Node).all()
+    {opensql}SELECT node_1.id AS node_1_id,
             node_1.parent_id AS node_1_parent_id,
             node_1.data AS node_1_data,
             node_2.id AS node_2_id,