MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_one_to_many_save

Method test_one_to_many_save

test/orm/test_unitofworkv2.py:871–919  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

869 conn.execute(self.tables.nodes.update().values(parent_id=None))
870
871 def test_one_to_many_save(self):
872 Node, nodes = self.classes.Node, self.tables.nodes
873
874 self.mapper_registry.map_imperatively(
875 Node, nodes, properties={"children": relationship(Node)}
876 )
877 sess = fixture_session()
878
879 n2, n3 = Node(data="n2"), Node(data="n3")
880 n1 = Node(data="n1", children=[n2, n3])
881
882 sess.add(n1)
883
884 self.assert_sql_execution(
885 testing.db,
886 sess.flush,
887 CompiledSQL(
888 "INSERT INTO nodes (parent_id, data) VALUES "
889 "(:parent_id, :data)",
890 {"parent_id": None, "data": "n1"},
891 ),
892 Conditional(
893 testing.db.dialect.insert_executemany_returning,
894 [
895 CompiledSQL(
896 "INSERT INTO nodes (parent_id, data) VALUES "
897 "(:parent_id, :data) RETURNING nodes.id",
898 lambda ctx: [
899 {"parent_id": n1.id, "data": "n2"},
900 {"parent_id": n1.id, "data": "n3"},
901 ],
902 ),
903 ],
904 [
905 AllOf(
906 CompiledSQL(
907 "INSERT INTO nodes (parent_id, data) VALUES "
908 "(:parent_id, :data)",
909 lambda ctx: {"parent_id": n1.id, "data": "n2"},
910 ),
911 CompiledSQL(
912 "INSERT INTO nodes (parent_id, data) VALUES "
913 "(:parent_id, :data)",
914 lambda ctx: {"parent_id": n1.id, "data": "n3"},
915 ),
916 ),
917 ],
918 ),
919 )
920
921 def test_one_to_many_delete_all(self):
922 Node, nodes = self.classes.Node, self.tables.nodes

Callers

nothing calls this directly

Calls 9

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
CompiledSQLClass · 0.90
ConditionalClass · 0.90
AllOfClass · 0.90
map_imperativelyMethod · 0.80
assert_sql_executionMethod · 0.80
NodeClass · 0.70
addMethod · 0.45

Tested by

no test coverage detected