(items: T[])
| 536 | } |
| 537 | |
| 538 | private validateModification(items: T[]): void { |
| 539 | if (this.#readonly) { |
| 540 | throw ValidationError.cannotModifyReadonlyCollection(this.owner, this.property); |
| 541 | } |
| 542 | |
| 543 | const check = (item: AnyEntity) => { |
| 544 | if (!item) { |
| 545 | return false; |
| 546 | } |
| 547 | |
| 548 | if (!Utils.isEntity(item)) { |
| 549 | throw ValidationError.notEntity(this.owner, this.property, item); |
| 550 | } |
| 551 | |
| 552 | // currently we allow persisting to inverse sides only in SQL drivers |
| 553 | if (this.property.pivotTable || !this.property.mappedBy) { |
| 554 | return false; |
| 555 | } |
| 556 | |
| 557 | if (helper(item).__initialized) { |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | return !item[this.property.mappedBy] && this.property.kind === ReferenceKind.MANY_TO_MANY; |
| 562 | }; |
| 563 | |
| 564 | // throw if we are modifying inverse side of M:N collection when owning side is initialized (would be ignored when persisting) |
| 565 | if (items.some(item => check(item))) { |
| 566 | throw ValidationError.cannotModifyInverseCollection(this.owner, this.property); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | /** Converts all items in the collection to plain DTO objects. */ |
| 571 | toArray<TT extends T>(): EntityDTO<TT>[] { |
no test coverage detected