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

Method test_selfref_relationship

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

Source from the content-addressed store, hash-verified

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