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

Method test_o2m_m2o

test/orm/test_cascade.py:4083–4134  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4081 "The `objects` parameter of `Session.flush` is deprecated"
4082 )
4083 def test_o2m_m2o(self):
4084 base, noninh_child = self.tables.base, self.tables.noninh_child
4085
4086 class Base(ComparableEntity):
4087 pass
4088
4089 class Child(ComparableEntity):
4090 pass
4091
4092 self.mapper_registry.map_imperatively(
4093 Base,
4094 base,
4095 properties={"children": relationship(Child, backref="parent")},
4096 )
4097 self.mapper_registry.map_imperatively(Child, noninh_child)
4098
4099 sess = fixture_session()
4100
4101 c1, c2 = Child(), Child()
4102 b1 = Base(descr="b1", children=[c1, c2])
4103 sess.add(b1)
4104
4105 assert c1 in sess.new
4106 assert c2 in sess.new
4107 sess.flush([b1])
4108
4109 # c1, c2 get cascaded into the session on o2m.
4110 # not sure if this is how I like this
4111 # to work but that's how it works for now.
4112 assert c1 in sess and c1 not in sess.new
4113 assert c2 in sess and c2 not in sess.new
4114 assert b1 in sess and b1 not in sess.new
4115
4116 sess = fixture_session()
4117 c1, c2 = Child(), Child()
4118 b1 = Base(descr="b1", children=[c1, c2])
4119 sess.add(b1)
4120 sess.flush([c1])
4121 # m2o, otoh, doesn't cascade up the other way.
4122 assert c1 in sess and c1 not in sess.new
4123 assert c2 in sess and c2 in sess.new
4124 assert b1 in sess and b1 in sess.new
4125
4126 sess = fixture_session()
4127 c1, c2 = Child(), Child()
4128 b1 = Base(descr="b1", children=[c1, c2])
4129 sess.add(b1)
4130 sess.flush([c1, c2])
4131 # m2o, otoh, doesn't cascade up the other way.
4132 assert c1 in sess and c1 not in sess.new
4133 assert c2 in sess and c2 not in sess.new
4134 assert b1 in sess and b1 in sess.new
4135
4136 @uses_deprecated(
4137 "The `objects` parameter of `Session.flush` is deprecated"

Callers

nothing calls this directly

Calls 7

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
map_imperativelyMethod · 0.80
ChildClass · 0.70
BaseClass · 0.70
addMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected