MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_lazy_options

Method test_lazy_options

test/orm/test_options.py:1818–1849  ·  view source on GitHub ↗

An eager relationship can be upgraded to a lazy relationship.

(self)

Source from the content-addressed store, hash-verified

1816 self.assert_sql_count(testing.db, go, 6)
1817
1818 def test_lazy_options(self):
1819 """An eager relationship can be upgraded to a lazy relationship."""
1820
1821 Address, addresses, users, User = (
1822 self.classes.Address,
1823 self.tables.addresses,
1824 self.tables.users,
1825 self.classes.User,
1826 )
1827
1828 self.mapper_registry.map_imperatively(
1829 User,
1830 users,
1831 properties=dict(
1832 addresses=relationship(
1833 self.mapper_registry.map_imperatively(Address, addresses),
1834 lazy="joined",
1835 )
1836 ),
1837 )
1838
1839 sess = fixture_session()
1840 result = (
1841 sess.query(User)
1842 .order_by(User.id)
1843 .options(sa.orm.lazyload(User.addresses))
1844 ).all()
1845
1846 def go():
1847 eq_(result, self.static.user_address_result)
1848
1849 self.sql_count_(4, go)
1850
1851 def test_option_propagate(self):
1852 users, items, order_items, Order, Item, User, orders = (

Callers

nothing calls this directly

Calls 9

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
map_imperativelyMethod · 0.80
sql_count_Method · 0.80
allMethod · 0.45
optionsMethod · 0.45
order_byMethod · 0.45
queryMethod · 0.45
lazyloadMethod · 0.45

Tested by

no test coverage detected