MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_deferred_fk_col

Method test_deferred_fk_col

test/orm/test_eager_relations.py:532–668  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

530 )
531
532 def test_deferred_fk_col(self):
533 users, Dingaling, User, dingalings, Address, addresses = (
534 self.tables.users,
535 self.classes.Dingaling,
536 self.classes.User,
537 self.tables.dingalings,
538 self.classes.Address,
539 self.tables.addresses,
540 )
541
542 self.mapper_registry.map_imperatively(
543 Address,
544 addresses,
545 properties={
546 "user_id": deferred(addresses.c.user_id),
547 "user": relationship(User, lazy="joined"),
548 },
549 )
550 self.mapper_registry.map_imperatively(User, users)
551
552 sess = fixture_session()
553
554 for q in [
555 sess.query(Address)
556 .filter(Address.id.in_([1, 4, 5]))
557 .order_by(Address.id),
558 sess.query(Address)
559 .filter(Address.id.in_([1, 4, 5]))
560 .order_by(Address.id)
561 .limit(3),
562 ]:
563 sess.expunge_all()
564 eq_(
565 q.all(),
566 [
567 Address(id=1, user=User(id=7)),
568 Address(id=4, user=User(id=8)),
569 Address(id=5, user=User(id=9)),
570 ],
571 )
572
573 sess.expunge_all()
574 a = sess.query(Address).filter(Address.id == 1).all()[0]
575
576 # 1.0 change! we don't automatically undefer user_id here.
577 # if the user wants a column undeferred, add the option.
578 def go():
579 eq_(a.user_id, 7)
580
581 # self.assert_sql_count(testing.db, go, 0)
582 self.assert_sql_count(testing.db, go, 1)
583
584 sess.expunge_all()
585 a = sess.query(Address).filter(Address.id == 1).first()
586
587 def go():
588 eq_(a.user_id, 7)
589

Callers

nothing calls this directly

Calls 15

deferredFunction · 0.90
relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
assert_sql_countMethod · 0.80
AddressClass · 0.70
UserClass · 0.70
order_byMethod · 0.45
filterMethod · 0.45
queryMethod · 0.45
in_Method · 0.45

Tested by

no test coverage detected