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:
parent
da6a90a042
commit
20b44c9dbd
|
@ -183,12 +183,14 @@ class LinkController {
|
|||
// iterate through the link IDs in the row field, see if any don't exist already
|
||||
for (let linkId of rowField) {
|
||||
if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) {
|
||||
const links = await getLinkDocuments({
|
||||
appId: this._appId,
|
||||
tableId: field.tableId,
|
||||
rowId: linkId,
|
||||
includeDocs: IncludeDocs.INCLUDE,
|
||||
})
|
||||
const links = (
|
||||
await getLinkDocuments({
|
||||
appId: this._appId,
|
||||
tableId: field.tableId,
|
||||
rowId: linkId,
|
||||
includeDocs: IncludeDocs.EXCLUDE,
|
||||
})
|
||||
).filter(link => link.id !== row._id)
|
||||
|
||||
// The 1 side of 1:N is already related to something else
|
||||
// You must remove the existing relationship
|
||||
|
@ -330,12 +332,7 @@ class LinkController {
|
|||
if (field.relationshipType) {
|
||||
// Ensure that the other side of the relationship is locked to one record
|
||||
linkConfig.relationshipType = 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
|
||||
delete field.relationshipType
|
||||
}
|
||||
|
||||
// check the linked table to make sure we aren't overwriting an existing column
|
||||
|
|
Loading…
Reference in New Issue