pr comments

This commit is contained in:
Peter Clement 2023-09-26 09:33:44 +01:00
parent db9c5db6e3
commit 8af8c33bbe
2 changed files with 26 additions and 33 deletions

View File

@ -78,26 +78,28 @@
editableColumn.constraints.presence = { allowEmpty: false } editableColumn.constraints.presence = { allowEmpty: false }
} }
$: { let relationshipMap = {
if (editableColumn.type === LINK_TYPE && editableColumn.tableId) { [RelationshipType.MANY_TO_ONE]: {
// Determine the relationship type based on the selected values of both parts part1: PrettyRelationshipDefinitions.MANY,
if ( part2: PrettyRelationshipDefinitions.ONE,
relationshipPart1 === PrettyRelationshipDefinitions.MANY && },
relationshipPart2 === PrettyRelationshipDefinitions.ONE [RelationshipType.MANY_TO_MANY]: {
) { part1: PrettyRelationshipDefinitions.MANY,
editableColumn.relationshipType = RelationshipType.MANY_TO_ONE part2: PrettyRelationshipDefinitions.MANY,
} else if ( },
relationshipPart1 === PrettyRelationshipDefinitions.MANY && [RelationshipType.ONE_TO_MANY]: {
relationshipPart2 === PrettyRelationshipDefinitions.MANY part1: PrettyRelationshipDefinitions.ONE,
) { part2: PrettyRelationshipDefinitions.MANY,
editableColumn.relationshipType = RelationshipType.MANY_TO_MANY },
} else if ( }
relationshipPart1 === PrettyRelationshipDefinitions.ONE &&
relationshipPart2 === PrettyRelationshipDefinitions.MANY
) {
editableColumn.relationshipType = RelationshipType.ONE_TO_MANY
}
$: {
if (editableColumn.type === LINK_TYPE) {
// Determine the relationship type based on the selected values of both parts
editableColumn.relationshipType = Object.entries(relationshipMap).find(
([_, parts]) =>
parts.part1 === relationshipPart1 && parts.part2 === relationshipPart2
)?.[0]
// Set the tableId based on the selected table // Set the tableId based on the selected table
editableColumn.tableId = relationshipTableIdSecondary editableColumn.tableId = relationshipTableIdSecondary
} }
@ -132,19 +134,11 @@
if (editableColumn.type === LINK_TYPE && editableColumn.tableId) { if (editableColumn.type === LINK_TYPE && editableColumn.tableId) {
relationshipTableIdSecondary = editableColumn.tableId relationshipTableIdSecondary = editableColumn.tableId
if (editableColumn.relationshipType === RelationshipType.MANY_TO_ONE) { if (editableColumn.relationshipType in relationshipMap) {
relationshipPart1 = PrettyRelationshipDefinitions.MANY const { part1, part2 } =
relationshipPart2 = PrettyRelationshipDefinitions.ONE relationshipMap[editableColumn.relationshipType]
} else if ( relationshipPart1 = part1
editableColumn.relationshipType === RelationshipType.MANY_TO_MANY relationshipPart2 = part2
) {
relationshipPart1 = PrettyRelationshipDefinitions.MANY
relationshipPart2 = PrettyRelationshipDefinitions.MANY
} else if (
editableColumn.relationshipType === RelationshipType.ONE_TO_MANY
) {
relationshipPart1 = PrettyRelationshipDefinitions.ONE
relationshipPart2 = PrettyRelationshipDefinitions.MANY
} }
} }
} }

View File

@ -10,7 +10,6 @@
export let linkEditDisabled export let linkEditDisabled
export let tableOptions export let tableOptions
export let errors export let errors
$: console.log(relationshipPart1)
</script> </script>
<div class="relationship-container"> <div class="relationship-container">