Mark the method as adding an entity to the collection. Adds "add to collection" handling to the method. The decorator argument indicates which method argument holds the SQLAlchemy-relevant value. Arguments can be specified positionally (i.e. integer) or by name::
(arg: int)
| 320 | |
| 321 | @staticmethod |
| 322 | def adds(arg: int) -> Callable[[_FN], _FN]: |
| 323 | """Mark the method as adding an entity to the collection. |
| 324 | |
| 325 | Adds "add to collection" handling to the method. The decorator |
| 326 | argument indicates which method argument holds the SQLAlchemy-relevant |
| 327 | value. Arguments can be specified positionally (i.e. integer) or by |
| 328 | name:: |
| 329 | |
| 330 | @collection.adds(1) |
| 331 | def push(self, item): ... |
| 332 | |
| 333 | |
| 334 | @collection.adds("entity") |
| 335 | def do_stuff(self, thing, entity=None): ... |
| 336 | |
| 337 | """ |
| 338 | |
| 339 | def decorator(fn): |
| 340 | fn._sa_instrument_before = ("fire_append_event", arg) |
| 341 | return fn |
| 342 | |
| 343 | return decorator |
| 344 | |
| 345 | @staticmethod |
| 346 | def replaces(arg): |