MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_selfref_relationship

Method test_selfref_relationship

test/orm/test_query.py:1817–1929  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1815 )
1816
1817 def test_selfref_relationship(self):
1818 Node = self.classes.Node
1819
1820 nalias = aliased(Node)
1821
1822 # auto self-referential aliasing
1823 self._test(
1824 Node.children.any(Node.data == "n1"),
1825 "EXISTS (SELECT 1 FROM nodes AS nodes_1 WHERE "
1826 "nodes.id = nodes_1.parent_id AND nodes_1.data = :data_1)",
1827 entity=Node,
1828 checkparams={"data_1": "n1"},
1829 )
1830
1831 # needs autoaliasing
1832 self._test(
1833 Node.children == None, # noqa
1834 "NOT (EXISTS (SELECT 1 FROM nodes AS nodes_1 "
1835 "WHERE nodes.id = nodes_1.parent_id))",
1836 entity=Node,
1837 checkparams={},
1838 )
1839
1840 self._test(
1841 Node.parent == None, # noqa
1842 "nodes.parent_id IS NULL",
1843 checkparams={},
1844 )
1845
1846 self._test(
1847 nalias.parent == None, # noqa
1848 "nodes_1.parent_id IS NULL",
1849 checkparams={},
1850 )
1851
1852 self._test(
1853 nalias.parent != None, # noqa
1854 "nodes_1.parent_id IS NOT NULL",
1855 checkparams={},
1856 )
1857
1858 self._test(
1859 nalias.children == None, # noqa
1860 "NOT (EXISTS ("
1861 "SELECT 1 FROM nodes WHERE nodes_1.id = nodes.parent_id))",
1862 entity=nalias,
1863 checkparams={},
1864 )
1865
1866 self._test(
1867 nalias.children.any(Node.data == "some data"),
1868 "EXISTS (SELECT 1 FROM nodes WHERE "
1869 "nodes_1.id = nodes.parent_id AND nodes.data = :data_1)",
1870 entity=nalias,
1871 checkparams={"data_1": "some data"},
1872 )
1873
1874 # this fails because self-referential any() is auto-aliasing;

Callers

nothing calls this directly

Calls 6

_testMethod · 0.95
aliasedFunction · 0.90
NodeClass · 0.70
anyMethod · 0.45
hasMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected