Fix for issue #2167, the foreign key was not being set correctly in all scenarios for the from table in SQL relationships, our test data happened to hide this fact due to the foreign key and the key in from table having the same name.

This commit is contained in:
mike12345567 2021-07-30 18:49:36 +01:00
parent 6f190345de
commit 6a4d39f29b
1 changed files with 8 additions and 2 deletions

View File

@ -158,10 +158,16 @@
fieldName: fromTable.primary[0], fieldName: fromTable.primary[0],
} }
} else { } else {
// the relateFrom.fieldName should remain the same, as it is the foreignKey in the other
// table, this is due to the way that budibase represents relationships, the fieldName in a
// link column schema is the column linked to (FK in this case). The foreignKey column is
// essentially what is linked to in the from table, this is unique to SQL as this isn't a feature
// of Budibase internal tables.
// Essentially this means the fieldName is what we are linking to in the other table, and the
// foreignKey is what is linking out of the current table.
relateFrom = { relateFrom = {
...relateFrom, ...relateFrom,
foreignKey: relateFrom.fieldName, foreignKey: fromTable.primary[0],
fieldName: fromTable.primary[0],
} }
relateTo = { relateTo = {
...relateTo, ...relateTo,