For one-to-many collections, produce a :class:`_dml.Insert` which will insert new rows in terms of this this instance-local :class:`_orm.WriteOnlyCollection`. This construct is only supported for a :class:`_orm.Relationship` that does **not** include the :paramref:`_
(self)
| 613 | return stmt |
| 614 | |
| 615 | def insert(self) -> Insert: |
| 616 | """For one-to-many collections, produce a :class:`_dml.Insert` which |
| 617 | will insert new rows in terms of this this instance-local |
| 618 | :class:`_orm.WriteOnlyCollection`. |
| 619 | |
| 620 | This construct is only supported for a :class:`_orm.Relationship` |
| 621 | that does **not** include the :paramref:`_orm.relationship.secondary` |
| 622 | parameter. For relationships that refer to a many-to-many table, |
| 623 | use ordinary bulk insert techniques to produce new objects, then |
| 624 | use :meth:`_orm.AbstractCollectionWriter.add_all` to associate them |
| 625 | with the collection. |
| 626 | |
| 627 | |
| 628 | """ |
| 629 | |
| 630 | state = inspect(self.instance) |
| 631 | mapper = state.mapper |
| 632 | prop = mapper._props[self.attr.key] |
| 633 | |
| 634 | if prop.direction is not RelationshipDirection.ONETOMANY: |
| 635 | raise exc.InvalidRequestError( |
| 636 | "Write only bulk INSERT only supported for one-to-many " |
| 637 | "collections; for many-to-many, use a separate bulk " |
| 638 | "INSERT along with add_all()." |
| 639 | ) |
| 640 | |
| 641 | dict_: Dict[str, Any] = {} |
| 642 | |
| 643 | for l, r in prop.synchronize_pairs: |
| 644 | fn = prop._get_attr_w_warn_on_none( |
| 645 | mapper, |
| 646 | state, |
| 647 | state.dict, |
| 648 | l, |
| 649 | ) |
| 650 | |
| 651 | dict_[r.key] = bindparam(None, callable_=fn) |
| 652 | |
| 653 | return insert(self.attr.target_mapper).values(**dict_) |
| 654 | |
| 655 | def update(self) -> Update: |
| 656 | """Produce a :class:`_dml.Update` which will refer to rows in terms |
no test coverage detected