(self, collection_class)
| 2118 | ) |
| 2119 | |
| 2120 | def _test_composite_mapped(self, collection_class): |
| 2121 | parents, children, Parent, Child = ( |
| 2122 | self.tables.parents, |
| 2123 | self.tables.children, |
| 2124 | self.classes.Parent, |
| 2125 | self.classes.Child, |
| 2126 | ) |
| 2127 | |
| 2128 | self.mapper_registry.map_imperatively(Child, children) |
| 2129 | self.mapper_registry.map_imperatively( |
| 2130 | Parent, |
| 2131 | parents, |
| 2132 | properties={ |
| 2133 | "children": relationship( |
| 2134 | Child, |
| 2135 | collection_class=collection_class, |
| 2136 | cascade="all, delete-orphan", |
| 2137 | ) |
| 2138 | }, |
| 2139 | ) |
| 2140 | |
| 2141 | p = Parent() |
| 2142 | p.children[("foo", "1")] = Child("foo", "1", "value 1") |
| 2143 | p.children[("foo", "2")] = Child("foo", "2", "value 2") |
| 2144 | |
| 2145 | session = fixture_session() |
| 2146 | session.add(p) |
| 2147 | session.flush() |
| 2148 | pid = p.id |
| 2149 | session.expunge_all() |
| 2150 | |
| 2151 | p = session.get(Parent, pid) |
| 2152 | |
| 2153 | self.assert_(set(p.children.keys()) == {("foo", "1"), ("foo", "2")}) |
| 2154 | cid = p.children[("foo", "1")].id |
| 2155 | |
| 2156 | collections.collection_adapter(p.children).append_with_event( |
| 2157 | Child("foo", "1", "newvalue") |
| 2158 | ) |
| 2159 | |
| 2160 | session.flush() |
| 2161 | session.expunge_all() |
| 2162 | |
| 2163 | p = session.get(Parent, pid) |
| 2164 | |
| 2165 | self.assert_(set(p.children.keys()) == {("foo", "1"), ("foo", "2")}) |
| 2166 | self.assert_(p.children[("foo", "1")].id != cid) |
| 2167 | |
| 2168 | self.assert_( |
| 2169 | len(list(collections.collection_adapter(p.children))) == 2 |
| 2170 | ) |
| 2171 | |
| 2172 | def test_mapped_collection(self): |
| 2173 | collection_class = collections.keyfunc_mapping(lambda c: c.a) |
no test coverage detected