MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_no_orphan

Method test_no_orphan

test/orm/test_lazy_relations.py:212–240  ·  view source on GitHub ↗

test that a lazily loaded child object is not marked as an orphan

(self)

Source from the content-addressed store, hash-verified

210 ] == sess.query(User).all()
211
212 def test_no_orphan(self):
213 """test that a lazily loaded child object is not marked as an orphan"""
214
215 users, Address, addresses, User = (
216 self.tables.users,
217 self.classes.Address,
218 self.tables.addresses,
219 self.classes.User,
220 )
221
222 self.mapper_registry.map_imperatively(
223 User,
224 users,
225 properties={
226 "addresses": relationship(
227 Address, cascade="all,delete-orphan", lazy="select"
228 )
229 },
230 )
231 self.mapper_registry.map_imperatively(Address, addresses)
232
233 sess = fixture_session()
234 user = sess.get(User, 7)
235 assert getattr(User, "addresses").hasparent(
236 attributes.instance_state(user.addresses[0]), optimistic=True
237 )
238 assert not sa.orm.class_mapper(Address)._is_orphan(
239 attributes.instance_state(user.addresses[0])
240 )
241
242 def test_limit(self):
243 """test limit operations combined with lazy-load relationships."""

Callers

nothing calls this directly

Calls 6

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
map_imperativelyMethod · 0.80
_is_orphanMethod · 0.80
getMethod · 0.45
hasparentMethod · 0.45

Tested by

no test coverage detected