| 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))) { |