MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_post_update_m2o

Method test_post_update_m2o

test/orm/test_cycles.py:896–1005  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

894 )
895
896 def test_post_update_m2o(self):
897 """A cycle between two rows, with a post_update on the many-to-one"""
898
899 person, ball, Ball, Person = (
900 self.tables.person,
901 self.tables.ball,
902 self.classes.Ball,
903 self.classes.Person,
904 )
905
906 self.mapper_registry.map_imperatively(Ball, ball)
907 self.mapper_registry.map_imperatively(
908 Person,
909 person,
910 properties=dict(
911 balls=relationship(
912 Ball,
913 primaryjoin=ball.c.person_id == person.c.id,
914 remote_side=ball.c.person_id,
915 post_update=False,
916 cascade="all, delete-orphan",
917 _legacy_inactive_history_style=(
918 self._legacy_inactive_history_style
919 ),
920 ),
921 favorite=relationship(
922 Ball,
923 primaryjoin=person.c.favorite_ball_id == ball.c.id,
924 post_update=True,
925 _legacy_inactive_history_style=(
926 self._legacy_inactive_history_style
927 ),
928 ),
929 ),
930 )
931
932 b = Ball(data="some data")
933 p = Person(data="some data")
934 p.balls.append(b)
935 p.balls.append(Ball(data="some data"))
936 p.balls.append(Ball(data="some data"))
937 p.balls.append(Ball(data="some data"))
938 p.favorite = b
939 sess = fixture_session()
940 sess.add(b)
941 sess.add(p)
942
943 self.assert_sql_execution(
944 testing.db,
945 sess.flush,
946 RegexSQL("^INSERT INTO person", {"data": "some data"}),
947 Conditional(
948 testing.db.dialect.insert_executemany_returning,
949 [
950 RegexSQL(
951 "^INSERT INTO ball",
952 lambda c: [
953 {"person_id": p.id, "data": "some data"},

Callers

nothing calls this directly

Calls 12

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
RegexSQLClass · 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
addMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected