tmp fix: relationship many

This commit is contained in:
Arman
2023-04-03 09:36:33 +02:00
parent 005714f3dd
commit 2059e4142b
2 changed files with 9 additions and 10 deletions
@@ -32,7 +32,7 @@
let offset = 0;
onMount(async () => {
teamPrefs.load($organization.$id);
await teamPrefs.load($organization.$id);
documentList = await getDocuments();
if (editing && $doc?.[attribute.key] && $doc[attribute.key]?.length) {
@@ -65,11 +65,11 @@
}
}
// Reactive statements
//Reactive statements
$: getDocuments(search).then((res) => (documentList = res));
$: if (isRelationshipToMany(attribute)) {
value = relatedList;
$: if (!!attribute?.type && isRelationshipToMany(attribute)) {
// value = relatedList;
} else {
value = singleRel;
}
@@ -80,7 +80,7 @@
.reverse()
.slice(offset, offset + limit)
: [];
$: total = relatedList?.length;
$: total = relatedList?.length ?? 0;
$: options =
documentList?.documents?.map((n) => {
const data = displayNames.filter((name) => name !== '$id').map((name) => n?.[name]);
@@ -114,7 +114,7 @@
</div>
<ul class="u-flex-vertical u-gap-4 u-margin-block-start-4">
{#if !editing}
{#if !editing && relatedList?.length}
{#each relatedList as item, i}
<li class="u-flex u-gap-16">
<InputSelectSearch
@@ -4,11 +4,10 @@ import type { Attributes } from '../../store';
//TODO: remove `side` after SDK update
export function isRelationshipToMany(attribute: Models.AttributeRelationship & { side: string }) {
if (!attribute) return false;
const { side, relationType } = attribute || {};
if (side === 'parent') {
return !['oneToOne', 'manyToOne'].includes(relationType);
if (attribute?.side === 'parent') {
return !['oneToOne', 'manyToOne'].includes(attribute?.relationType);
} else {
return !['oneToOne', 'oneToMany'].includes(relationType);
return !['oneToOne', 'oneToMany'].includes(attribute?.relationType);
}
}