MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_self_referential_roundtrip

Method test_self_referential_roundtrip

test/orm/test_manytomany.py:146–192  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

144 )
145
146 def test_self_referential_roundtrip(self):
147 place, Place, place_place = (
148 self.tables.place,
149 self.classes.Place,
150 self.tables.place_place,
151 )
152
153 self.mapper_registry.map_imperatively(
154 Place,
155 place,
156 properties={
157 "places": relationship(
158 Place,
159 secondary=place_place,
160 primaryjoin=place.c.place_id == place_place.c.pl1_id,
161 secondaryjoin=place.c.place_id == place_place.c.pl2_id,
162 order_by=place_place.c.pl2_id,
163 )
164 },
165 )
166
167 sess = fixture_session()
168 p1 = Place("place1")
169 p2 = Place("place2")
170 p3 = Place("place3")
171 p4 = Place("place4")
172 p5 = Place("place5")
173 p6 = Place("place6")
174 p7 = Place("place7")
175 sess.add_all((p1, p2, p3, p4, p5, p6, p7))
176 p1.places.append(p2)
177 p1.places.append(p3)
178 p5.places.append(p6)
179 p6.places.append(p1)
180 p7.places.append(p1)
181 p1.places.append(p5)
182 p4.places.append(p3)
183 p3.places.append(p4)
184 sess.commit()
185
186 eq_(p1.places, [p2, p3, p5])
187 eq_(p5.places, [p6])
188 eq_(p7.places, [p1])
189 eq_(p6.places, [p1])
190 eq_(p4.places, [p3])
191 eq_(p3.places, [p4])
192 eq_(p2.places, [])
193
194 def test_self_referential_bidirectional_mutation(self):
195 place, Place, place_place = (

Callers

nothing calls this directly

Calls 8

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
PlaceClass · 0.85
map_imperativelyMethod · 0.80
add_allMethod · 0.45
appendMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected