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

Method test_no_orphan

test/orm/test_eager_relations.py:292–321  ·  view source on GitHub ↗

An eagerly loaded child object is not marked as an orphan

(self)

Source from the content-addressed store, hash-verified

290 self.assert_sql_count(testing.db, go, 1)
291
292 def test_no_orphan(self):
293 """An eagerly loaded child object is not marked as an orphan"""
294
295 users, Address, addresses, User = (
296 self.tables.users,
297 self.classes.Address,
298 self.tables.addresses,
299 self.classes.User,
300 )
301
302 self.mapper_registry.map_imperatively(
303 User,
304 users,
305 properties={
306 "addresses": relationship(
307 Address, cascade="all,delete-orphan", lazy="joined"
308 )
309 },
310 )
311 self.mapper_registry.map_imperatively(Address, addresses)
312
313 sess = fixture_session()
314 user = sess.get(User, 7)
315 assert getattr(User, "addresses").hasparent(
316 sa.orm.attributes.instance_state(user.addresses[0]),
317 optimistic=True,
318 )
319 assert not sa.orm.class_mapper(Address)._is_orphan(
320 sa.orm.attributes.instance_state(user.addresses[0])
321 )
322
323 def test_orderby(self):
324 users, Address, addresses, User = (

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