Updating reactivity to fix issues with occasionally incorrect errors.
This commit is contained in:
parent
21556c215a
commit
2807fbd4b6
|
@ -47,13 +47,7 @@
|
||||||
relationshipExists
|
relationshipExists
|
||||||
)
|
)
|
||||||
let errors = {}
|
let errors = {}
|
||||||
let fromPrimary,
|
let fromPrimary, fromForeign, fromColumn, toColumn
|
||||||
fromForeign,
|
|
||||||
fromTable,
|
|
||||||
toTable,
|
|
||||||
throughTable,
|
|
||||||
fromColumn,
|
|
||||||
toColumn
|
|
||||||
let fromId = selectedFromTable?._id,
|
let fromId = selectedFromTable?._id,
|
||||||
toId,
|
toId,
|
||||||
throughId,
|
throughId,
|
||||||
|
@ -69,11 +63,20 @@
|
||||||
$: valid = getErrorCount(errors) === 0 && allRequiredAttributesSet()
|
$: valid = getErrorCount(errors) === 0 && allRequiredAttributesSet()
|
||||||
$: isManyToMany = relationshipType === RelationshipTypes.MANY_TO_MANY
|
$: isManyToMany = relationshipType === RelationshipTypes.MANY_TO_MANY
|
||||||
$: isManyToOne = relationshipType === RelationshipTypes.MANY_TO_ONE
|
$: isManyToOne = relationshipType === RelationshipTypes.MANY_TO_ONE
|
||||||
$: fromTable = plusTables.find(table => table._id === fromId)
|
|
||||||
$: toTable = plusTables.find(table => table._id === toId)
|
|
||||||
$: throughTable = plusTables.find(table => table._id === throughId)
|
|
||||||
$: toRelationship.relationshipType = fromRelationship?.relationshipType
|
$: toRelationship.relationshipType = fromRelationship?.relationshipType
|
||||||
|
|
||||||
|
function getFromTable() {
|
||||||
|
return plusTables.find(table => table._id === fromId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getToTable() {
|
||||||
|
return plusTables.find(table => table._id === toId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getThroughTable() {
|
||||||
|
return plusTables.find(table => table._id === throughId)
|
||||||
|
}
|
||||||
|
|
||||||
function invalidThroughTable() {
|
function invalidThroughTable() {
|
||||||
// need to know the foreign key columns to check error
|
// need to know the foreign key columns to check error
|
||||||
if (!throughId || !throughToKey || !throughFromKey) {
|
if (!throughId || !throughToKey || !throughFromKey) {
|
||||||
|
@ -94,16 +97,16 @@
|
||||||
if (
|
if (
|
||||||
originalFromTable &&
|
originalFromTable &&
|
||||||
originalToTable &&
|
originalToTable &&
|
||||||
originalFromTable === fromTable &&
|
originalFromTable === getFromTable() &&
|
||||||
originalToTable === toTable
|
originalToTable === getToTable()
|
||||||
) {
|
) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let fromThroughLinks = Object.values(
|
let fromThroughLinks = Object.values(
|
||||||
datasource.entities[fromTable.name].schema
|
datasource.entities[getFromTable().name].schema
|
||||||
).filter(value => value.through)
|
).filter(value => value.through)
|
||||||
let toThroughLinks = Object.values(
|
let toThroughLinks = Object.values(
|
||||||
datasource.entities[toTable.name].schema
|
datasource.entities[getToTable().name].schema
|
||||||
).filter(value => value.through)
|
).filter(value => value.through)
|
||||||
|
|
||||||
const matchAgainstUserInput = (fromTableId, toTableId) =>
|
const matchAgainstUserInput = (fromTableId, toTableId) =>
|
||||||
|
@ -124,11 +127,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function allRequiredAttributesSet() {
|
function allRequiredAttributesSet() {
|
||||||
const base = fromTable && toTable && fromColumn && toColumn
|
const base = getFromTable() && getToTable() && fromColumn && toColumn
|
||||||
if (relationshipType === RelationshipTypes.MANY_TO_ONE) {
|
if (relationshipType === RelationshipTypes.MANY_TO_ONE) {
|
||||||
return base && fromPrimary && fromForeign
|
return base && fromPrimary && fromForeign
|
||||||
} else {
|
} else {
|
||||||
return base && throughTable && throughFromKey && throughToKey
|
return base && getThroughTable() && throughFromKey && throughToKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +141,9 @@
|
||||||
}
|
}
|
||||||
hasValidated = true
|
hasValidated = true
|
||||||
errorChecker.setType(relationshipType)
|
errorChecker.setType(relationshipType)
|
||||||
|
const fromTable = getFromTable(),
|
||||||
|
toTable = getToTable(),
|
||||||
|
throughTable = getThroughTable()
|
||||||
errors = {
|
errors = {
|
||||||
relationshipType: errorChecker.relationshipTypeSet(relationshipType),
|
relationshipType: errorChecker.relationshipTypeSet(relationshipType),
|
||||||
fromTable:
|
fromTable:
|
||||||
|
@ -210,13 +216,13 @@
|
||||||
if (manyToMany) {
|
if (manyToMany) {
|
||||||
relateFrom = {
|
relateFrom = {
|
||||||
...relateFrom,
|
...relateFrom,
|
||||||
through: throughTable._id,
|
through: getThroughTable()._id,
|
||||||
fieldName: toTable.primary[0],
|
fieldName: getToTable().primary[0],
|
||||||
}
|
}
|
||||||
relateTo = {
|
relateTo = {
|
||||||
...relateTo,
|
...relateTo,
|
||||||
through: throughTable._id,
|
through: getThroughTable()._id,
|
||||||
fieldName: fromTable.primary[0],
|
fieldName: getFromTable().primary[0],
|
||||||
throughFrom: relateFrom.throughTo,
|
throughFrom: relateFrom.throughTo,
|
||||||
throughTo: relateFrom.throughFrom,
|
throughTo: relateFrom.throughFrom,
|
||||||
}
|
}
|
||||||
|
@ -265,10 +271,10 @@
|
||||||
removeExistingRelationship()
|
removeExistingRelationship()
|
||||||
|
|
||||||
// source of relationship
|
// source of relationship
|
||||||
datasource.entities[fromTable.name].schema[fromRelationship.name] =
|
datasource.entities[getFromTable().name].schema[fromRelationship.name] =
|
||||||
fromRelationship
|
fromRelationship
|
||||||
// save other side of relationship in the other schema
|
// save other side of relationship in the other schema
|
||||||
datasource.entities[toTable.name].schema[toRelationship.name] =
|
datasource.entities[getToTable().name].schema[toRelationship.name] =
|
||||||
toRelationship
|
toRelationship
|
||||||
|
|
||||||
await save()
|
await save()
|
||||||
|
@ -343,10 +349,10 @@
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if isManyToOne && fromTable}
|
{#if isManyToOne && fromId}
|
||||||
<Select
|
<Select
|
||||||
label={`Primary Key (${fromTable.name})`}
|
label={`Primary Key (${getFromTable().name})`}
|
||||||
options={Object.keys(fromTable.schema)}
|
options={Object.keys(getFromTable().schema)}
|
||||||
bind:value={fromPrimary}
|
bind:value={fromPrimary}
|
||||||
bind:error={errors.fromPrimary}
|
bind:error={errors.fromPrimary}
|
||||||
on:change={changed}
|
on:change={changed}
|
||||||
|
@ -376,10 +382,10 @@
|
||||||
throughFromKey = null
|
throughFromKey = null
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
{#if fromTable && toTable && throughTable}
|
{#if fromId && toId && throughId}
|
||||||
<Select
|
<Select
|
||||||
label={`Foreign Key (${fromTable?.name})`}
|
label={`Foreign Key (${getFromTable()?.name})`}
|
||||||
options={Object.keys(throughTable?.schema)}
|
options={Object.keys(getThroughTable()?.schema)}
|
||||||
bind:value={throughToKey}
|
bind:value={throughToKey}
|
||||||
bind:error={errors.throughToKey}
|
bind:error={errors.throughToKey}
|
||||||
on:change={e =>
|
on:change={e =>
|
||||||
|
@ -390,8 +396,8 @@
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
label={`Foreign Key (${toTable?.name})`}
|
label={`Foreign Key (${getToTable()?.name})`}
|
||||||
options={Object.keys(throughTable?.schema)}
|
options={Object.keys(getThroughTable()?.schema)}
|
||||||
bind:value={throughFromKey}
|
bind:value={throughFromKey}
|
||||||
bind:error={errors.throughFromKey}
|
bind:error={errors.throughFromKey}
|
||||||
on:change={e =>
|
on:change={e =>
|
||||||
|
@ -402,10 +408,10 @@
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{:else if isManyToOne && toTable}
|
{:else if isManyToOne && toId}
|
||||||
<Select
|
<Select
|
||||||
label={`Foreign Key (${toTable?.name})`}
|
label={`Foreign Key (${getToTable()?.name})`}
|
||||||
options={Object.keys(toTable?.schema)}
|
options={Object.keys(getToTable()?.schema)}
|
||||||
bind:value={fromForeign}
|
bind:value={fromForeign}
|
||||||
bind:error={errors.fromForeign}
|
bind:error={errors.fromForeign}
|
||||||
on:change={changed}
|
on:change={changed}
|
||||||
|
|
Loading…
Reference in New Issue