Minor update to fix an issue when updating a row that it would throw an error with 1->to->many relationships on existing relationships for that row, as well as cleaning up how relationshipType is put onto the linked table.

This commit is contained in:
mike12345567 2021-02-25 17:07:32 +00:00
parent da6a90a042
commit 20b44c9dbd
1 changed files with 9 additions and 12 deletions

View File

@ -183,12 +183,14 @@ class LinkController {
// iterate through the link IDs in the row field, see if any don't exist already // iterate through the link IDs in the row field, see if any don't exist already
for (let linkId of rowField) { for (let linkId of rowField) {
if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) { if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) {
const links = await getLinkDocuments({ const links = (
appId: this._appId, await getLinkDocuments({
tableId: field.tableId, appId: this._appId,
rowId: linkId, tableId: field.tableId,
includeDocs: IncludeDocs.INCLUDE, rowId: linkId,
}) includeDocs: IncludeDocs.EXCLUDE,
})
).filter(link => link.id !== row._id)
// The 1 side of 1:N is already related to something else // The 1 side of 1:N is already related to something else
// You must remove the existing relationship // You must remove the existing relationship
@ -330,12 +332,7 @@ class LinkController {
if (field.relationshipType) { if (field.relationshipType) {
// Ensure that the other side of the relationship is locked to one record // Ensure that the other side of the relationship is locked to one record
linkConfig.relationshipType = field.relationshipType linkConfig.relationshipType = field.relationshipType
delete field.relationshipType
// Update this table to be the many
table.schema[field.name].relationshipType =
RelationshipTypes.MANY_TO_MANY
const response = await this._db.put(table)
table._rev = response.rev
} }
// check the linked table to make sure we aren't overwriting an existing column // check the linked table to make sure we aren't overwriting an existing column