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)
| 593 | return stmt |
| 594 | |
| 595 | def insert(self) -> Insert: |
| 596 | """For one-to-many collections, produce a :class:`_dml.Insert` which |
| 597 | will insert new rows in terms of this this instance-local |
| 598 | :class:`_orm.WriteOnlyCollection`. |
| 599 | |
| 600 | This construct is only supported for a :class:`_orm.Relationship` |
| 601 | that does **not** include the :paramref:`_orm.relationship.secondary` |
| 602 | parameter. For relationships that refer to a many-to-many table, |
| 603 | use ordinary bulk insert techniques to produce new objects, then |
| 604 | use :meth:`_orm.AbstractCollectionWriter.add_all` to associate them |
| 605 | with the collection. |
| 606 | |
| 607 | |
| 608 | """ |
| 609 | |
| 610 | state = inspect(self.instance) |
| 611 | mapper = state.mapper |
| 612 | prop = mapper._props[self.attr.key] |
| 613 | |
| 614 | if prop.direction is not RelationshipDirection.ONETOMANY: |
| 615 | raise exc.InvalidRequestError( |
| 616 | "Write only bulk INSERT only supported for one-to-many " |
| 617 | "collections; for many-to-many, use a separate bulk " |
| 618 | "INSERT along with add_all()." |
| 619 | ) |
| 620 | |
| 621 | dict_: Dict[str, Any] = {} |
| 622 | |
| 623 | for l, r in prop.synchronize_pairs: |
| 624 | fn = prop._get_attr_w_warn_on_none( |
| 625 | mapper, |
| 626 | state, |
| 627 | state.dict, |
| 628 | l, |
| 629 | ) |
| 630 | |
| 631 | dict_[r.key] = bindparam(None, callable_=fn) |
| 632 | |
| 633 | return insert(self.attr.target_mapper).values(**dict_) |
| 634 | |
| 635 | def update(self) -> Update: |
| 636 | """Produce a :class:`_dml.Update` which will refer to rows in terms |
no test coverage detected