| | 214 | def test_upgrade_local_colname(self): |
| | 215 | elixir.options.M2MCOL_NAMEFORMAT = elixir.options.OLD_M2MCOL_NAMEFORMAT |
| | 216 | |
| | 217 | class A(Entity): |
| | 218 | using_options(shortnames=True) |
| | 219 | name = Field(String(20)) |
| | 220 | links_to = ManyToMany('A') |
| | 221 | is_linked_from = ManyToMany('A') |
| | 222 | bs_ = ManyToMany('B') |
| | 223 | |
| | 224 | class B(Entity): |
| | 225 | using_options(shortnames=True) |
| | 226 | name = Field(String(20)) |
| | 227 | as_ = ManyToMany('A') |
| | 228 | |
| | 229 | setup_all(True) |
| | 230 | |
| | 231 | a = A(name='a1', links_to=[A(name='a2')]) |
| | 232 | |
| | 233 | session.commit() |
| | 234 | session.clear() |
| | 235 | |
| | 236 | del A |
| | 237 | del B |
| | 238 | |
| | 239 | # do not drop the tables, that's the whole point! |
| | 240 | cleanup_all() |
| | 241 | |
| | 242 | # ... |
| | 243 | elixir.options.M2MCOL_NAMEFORMAT = elixir.options.NEW_M2MCOL_NAMEFORMAT |
| | 244 | # elixir.options.MIGRATION_TO_07_AID = True |
| | 245 | |
| | 246 | class A(Entity): |
| | 247 | using_options(shortnames=True) |
| | 248 | name = Field(String(20)) |
| | 249 | links_to = ManyToMany('A', local_colname='a_id1') |
| | 250 | is_linked_from = ManyToMany('A', local_colname='a_id2') |
| | 251 | bs_ = ManyToMany('B') |
| | 252 | |
| | 253 | class B(Entity): |
| | 254 | using_options(shortnames=True) |
| | 255 | name = Field(String(20)) |
| | 256 | as_ = ManyToMany('A') |
| | 257 | |
| | 258 | setup_all() |
| | 259 | |
| | 260 | a1 = A.get_by(name='a1') |
| | 261 | assert len(a1.links_to) == 1 |
| | 262 | assert not a1.is_linked_from |
| | 263 | |
| | 264 | a2 = a1.links_to[0] |
| | 265 | assert a2.name == 'a2' |
| | 266 | assert not a2.links_to |
| | 267 | assert a2.is_linked_from == [a1] |
| | 268 | |