@ -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