MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_option_propagate

Method test_option_propagate

test/orm/test_options.py:1861–1913  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1859 self.sql_count_(4, go)
1860
1861 def test_option_propagate(self):
1862 users, items, order_items, Order, Item, User, orders = (
1863 self.tables.users,
1864 self.tables.items,
1865 self.tables.order_items,
1866 self.classes.Order,
1867 self.classes.Item,
1868 self.classes.User,
1869 self.tables.orders,
1870 )
1871
1872 self.mapper_registry.map_imperatively(
1873 User, users, properties=dict(orders=relationship(Order))
1874 )
1875 self.mapper_registry.map_imperatively(
1876 Order,
1877 orders,
1878 properties=dict(items=relationship(Item, secondary=order_items)),
1879 )
1880 self.mapper_registry.map_imperatively(Item, items)
1881
1882 sess = fixture_session()
1883
1884 oalias = aliased(Order)
1885
1886 # this one is *really weird*
1887 # here's what the test originally had. note two different strategies
1888 # for Order.items
1889 #
1890 # opt1 = sa.orm.joinedload(User.orders, Order.items)
1891 # opt2 = sa.orm.contains_eager(User.orders, Order.items, alias=oalias)
1892
1893 # here's how it would translate. note that the second
1894 # contains_eager() for Order.items just got cancelled out,
1895 # I guess the joinedload() would somehow overrule the contains_eager
1896 #
1897 # opt1 = Load(User).defaultload(User.orders).joinedload(Order.items)
1898 # opt2 = Load(User).contains_eager(User.orders, alias=oalias)
1899
1900 # setting up the options more specifically works however with
1901 # both the old way and the new way
1902 opt1 = sa.orm.joinedload(User.orders, Order.items)
1903 opt2 = sa.orm.contains_eager(User.orders, alias=oalias)
1904
1905 u1 = (
1906 sess.query(User)
1907 .join(oalias, User.orders)
1908 .options(opt1, opt2)
1909 .first()
1910 )
1911 ustate = attributes.instance_state(u1)
1912 assert opt1 in ustate.load_options
1913 assert opt2 not in ustate.load_options
1914
1915 @testing.combinations(
1916 (

Callers

nothing calls this directly

Calls 10

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
aliasedFunction · 0.90
map_imperativelyMethod · 0.80
joinedloadMethod · 0.80
contains_eagerMethod · 0.80
firstMethod · 0.45
optionsMethod · 0.45
joinMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected