diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-12-28 09:33:07 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-12-28 09:36:41 -0500 |
commit | e004da10d86d10d231b44d565621d8d5bcb3b81f (patch) | |
tree | 7f6e87fce6331d0d251ef2e12dc19200d54b6017 | |
parent | afed8c2b70f78684b8eb19eefbd3939b5699d4e6 (diff) | |
download | sqlalchemy-e004da10d86d10d231b44d565621d8d5bcb3b81f.tar.gz |
Add missing disambiguation to non-primary mapper example
The mapping to B over a join defines an alternate primary key
based on all the primary key columns in the join unless we
re-define it explicitly. Similarly, people expect that
``.id`` looks the same. make sure these line up with the
old mapping.
Change-Id: I1ab064c57019e79c34293f6588d1e033f7083974
(cherry picked from commit 16f08cbed5ff4f0f0b08dbd0dbd6e49aaee79163)
-rw-r--r-- | doc/build/orm/join_conditions.rst | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/doc/build/orm/join_conditions.rst b/doc/build/orm/join_conditions.rst index c39b7312e..818e637ec 100644 --- a/doc/build/orm/join_conditions.rst +++ b/doc/build/orm/join_conditions.rst @@ -699,10 +699,18 @@ the rows in both ``A`` and ``B`` simultaneously:: # 2. Create a new mapper() to B, with non_primary=True. # Columns in the join with the same name must be # disambiguated within the mapping, using named properties. - B_viacd = mapper(B, j, non_primary=True, properties={ - "b_id": [j.c.b_id, j.c.d_b_id], - "d_id": j.c.d_id - }) + # we also have to make sure the primary key of the regular "B" + # mapping is maintained. + B_viacd = mapper( + B, j, non_primary=True, primary_key=[j.c.b_id], + properties={ + "id": j.c.b_id, # so that 'id' looks the same as before + "c_id": j.c.c_id, # needed for disambiguation + "d_c_id": j.c.d_c_id, # needed for disambiguation + "b_id": [j.c.b_id, j.c.d_b_id], + "d_id": j.c.d_id, + } + ) A.b = relationship(B_viacd, primaryjoin=A.b_id == B_viacd.c.b_id) |