(association)
| 810 | |
| 811 | // Disassociate currently persisted models that are no longer associated |
| 812 | _disassociateFromHasManyInverses(association) { |
| 813 | let fk = association.getForeignKey(); |
| 814 | let tempAssociation = |
| 815 | this._tempAssociations && this._tempAssociations[association.name]; |
| 816 | let associateIds = this.attrs[fk]; |
| 817 | |
| 818 | if (tempAssociation && associateIds) { |
| 819 | let models; |
| 820 | if (association.isPolymorphic) { |
| 821 | models = associateIds.map(({ type, id }) => { |
| 822 | return this._schema[this._schema.toCollectionName(type)].find(id); |
| 823 | }); |
| 824 | } else { |
| 825 | // TODO: prob should initialize hasMany fks with [] |
| 826 | models = this._schema[ |
| 827 | this._schema.toCollectionName(association.modelName) |
| 828 | ].find(associateIds || []).models; |
| 829 | } |
| 830 | |
| 831 | models |
| 832 | .filter( |
| 833 | (associate) => |
| 834 | // filter out models that are already being saved |
| 835 | !associate.isSaving && |
| 836 | // filter out models that will still be associated |
| 837 | !tempAssociation.includes(associate) && |
| 838 | associate.hasInverseFor(association) |
| 839 | ) |
| 840 | .forEach((associate) => { |
| 841 | let inverse = associate.inverseFor(association); |
| 842 | |
| 843 | associate.disassociate(this, inverse); |
| 844 | associate.save(); |
| 845 | }); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | /* |
| 850 | Disassociate currently persisted models that are no longer associated. |
no test coverage detected