MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_post_update_o2m

Method test_post_update_o2m

test/orm/test_cycles.py:1071–1205  ·  view source on GitHub ↗

A cycle between two rows, with a post_update on the one-to-many

(self)

Source from the content-addressed store, hash-verified

1069 eq_(p3, b1.person)
1070
1071 def test_post_update_o2m(self):
1072 """A cycle between two rows, with a post_update on the one-to-many"""
1073
1074 person, ball, Ball, Person = (
1075 self.tables.person,
1076 self.tables.ball,
1077 self.classes.Ball,
1078 self.classes.Person,
1079 )
1080
1081 self.mapper_registry.map_imperatively(Ball, ball)
1082 self.mapper_registry.map_imperatively(
1083 Person,
1084 person,
1085 properties=dict(
1086 balls=relationship(
1087 Ball,
1088 primaryjoin=ball.c.person_id == person.c.id,
1089 remote_side=ball.c.person_id,
1090 cascade="all, delete-orphan",
1091 post_update=True,
1092 backref="person",
1093 _legacy_inactive_history_style=(
1094 self._legacy_inactive_history_style
1095 ),
1096 ),
1097 favorite=relationship(
1098 Ball,
1099 primaryjoin=person.c.favorite_ball_id == ball.c.id,
1100 _legacy_inactive_history_style=(
1101 self._legacy_inactive_history_style
1102 ),
1103 ),
1104 ),
1105 )
1106
1107 b = Ball(data="some data")
1108 p = Person(data="some data")
1109 p.balls.append(b)
1110 b2 = Ball(data="some data")
1111 p.balls.append(b2)
1112 b3 = Ball(data="some data")
1113 p.balls.append(b3)
1114 b4 = Ball(data="some data")
1115 p.balls.append(b4)
1116 p.favorite = b
1117 sess = fixture_session()
1118 sess.add_all((b, p, b2, b3, b4))
1119
1120 self.assert_sql_execution(
1121 testing.db,
1122 sess.flush,
1123 Conditional(
1124 testing.db.dialect.insert_executemany_returning,
1125 [
1126 CompiledSQL(
1127 "INSERT INTO ball (person_id, data) "
1128 "VALUES (:person_id, :data) RETURNING ball.id",

Callers

nothing calls this directly

Calls 11

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
ConditionalClass · 0.90
CompiledSQLClass · 0.90
BallClass · 0.85
map_imperativelyMethod · 0.80
assert_sql_executionMethod · 0.80
PersonClass · 0.70
appendMethod · 0.45
add_allMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected