mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-01 04:35:46 +00:00
Fix relations (#8097)
This commit is contained in:
parent
af22062112
commit
e33eac09b5
@ -1102,7 +1102,7 @@ export class LiveQuery implements WithTx, Client {
|
||||
if (res === undefined) return
|
||||
const association = this.getModel().findObject(assoc[0])
|
||||
if (association === undefined) return
|
||||
const docToPush = await this.findOne(!direct ? association.classB : association.classA, {
|
||||
const docToPush = await this.findOne(direct ? association.classB : association.classA, {
|
||||
_id: direct ? relation.docB : relation.docA
|
||||
})
|
||||
if (docToPush === undefined) return
|
||||
|
@ -52,7 +52,7 @@
|
||||
/>
|
||||
</div>
|
||||
<span class="label no-underline nowrap" class:fs-bold={accent}>
|
||||
{#if openIssues && (isAdminUser() || value.members.includes(getCurrentAccount()._id))}
|
||||
{#if openIssues && (isAdminUser() || value.members?.includes(getCurrentAccount()._id))}
|
||||
<NavLink space={value._id} special={'issues'} noUnderline={false}>
|
||||
{value.name}
|
||||
</NavLink>
|
||||
|
@ -31,8 +31,8 @@
|
||||
if (result != null) {
|
||||
const client = getClient()
|
||||
await client.createDoc(core.class.Relation, core.space.Workspace, {
|
||||
docA: direction === 'A' ? object._id : result._id,
|
||||
docB: direction === 'A' ? result._id : object._id,
|
||||
docA: direction === 'B' ? object._id : result._id,
|
||||
docB: direction === 'B' ? result._id : object._id,
|
||||
association: association._id
|
||||
})
|
||||
}
|
||||
@ -76,13 +76,19 @@
|
||||
)
|
||||
} else {
|
||||
preferenceQuery.unsubscribe()
|
||||
preference = undefined
|
||||
}
|
||||
|
||||
$: config = preference?.config ?? viewlet?.config
|
||||
$: selectedConfig = preference?.config ?? viewlet?.config
|
||||
$: config = selectedConfig?.filter((p) =>
|
||||
typeof p === 'string'
|
||||
? !p.includes('$lookup') && !p.startsWith('@')
|
||||
: !p.key.includes('$lookup') && !p.key.startsWith('@')
|
||||
)
|
||||
|
||||
async function onContextMenu (ev: MouseEvent, doc: Doc): Promise<void> {
|
||||
const q =
|
||||
direction === 'A'
|
||||
direction === 'B'
|
||||
? { docA: object._id, docB: doc._id, association: association._id }
|
||||
: { docA: doc._id, docB: object._id, association: association._id }
|
||||
const relation = await client.findOne(core.class.Relation, q)
|
||||
@ -90,12 +96,20 @@
|
||||
showMenu(ev, { object: relation, includedActions: [view.action.Delete] })
|
||||
}
|
||||
}
|
||||
|
||||
function isAllowedToCreate (association: Association, docs: Doc[], direction: 'A' | 'B'): boolean {
|
||||
if (docs.length === 0 || association.type === 'N:N') return true
|
||||
if (association.type === '1:1') return false
|
||||
return direction === 'B'
|
||||
}
|
||||
|
||||
$: allowToCreate = isAllowedToCreate(association, docs, direction)
|
||||
</script>
|
||||
|
||||
<Section {label}>
|
||||
<svelte:fragment slot="header">
|
||||
<div class="buttons-group xsmall-gap">
|
||||
{#if !readonly}
|
||||
{#if !readonly && allowToCreate}
|
||||
<Button id={core.string.AddRelation} icon={IconAdd} kind={'ghost'} on:click={add} />
|
||||
{/if}
|
||||
</div>
|
||||
|
@ -52,7 +52,7 @@
|
||||
(res) => {
|
||||
relationsA = res?.[0]?.$associations ?? {}
|
||||
},
|
||||
{ associations: associationsA.map((a) => [a._id, 1]) }
|
||||
{ associations: associationsA.map((a) => [a._id, -1]) }
|
||||
)
|
||||
|
||||
const queryB = createQuery()
|
||||
@ -62,7 +62,7 @@
|
||||
(res) => {
|
||||
relationsB = res?.[0]?.$associations ?? {}
|
||||
},
|
||||
{ associations: associationsB.map((a) => [a._id, -1]) }
|
||||
{ associations: associationsB.map((a) => [a._id, 1]) }
|
||||
)
|
||||
</script>
|
||||
|
||||
|
@ -876,9 +876,13 @@ abstract class PostgresAdapterBase implements DbAdapter {
|
||||
}
|
||||
}
|
||||
} else if (column.startsWith('assoc_')) {
|
||||
if (row[column] == null) continue
|
||||
const keys = column.split('_')
|
||||
const key = keys[keys.length - 1]
|
||||
associations[key] = row[column]
|
||||
const associationDomain = keys[1]
|
||||
const associationSchema = getSchema(associationDomain)
|
||||
const parsed = row[column].map((p: any) => parseDoc(p, associationSchema))
|
||||
associations[key] = parsed
|
||||
} else {
|
||||
joinIndex = undefined
|
||||
if (!map.has(row._id)) {
|
||||
@ -1433,17 +1437,18 @@ abstract class PostgresAdapterBase implements DbAdapter {
|
||||
}
|
||||
const isReverse = association[1] === -1
|
||||
const _class = isReverse ? assoc.classA : assoc.classB
|
||||
const tagetDomain = translateDomain(this.hierarchy.getDomain(_class))
|
||||
const keyA = isReverse ? 'docB' : 'docA'
|
||||
const keyB = isReverse ? 'docA' : 'docB'
|
||||
const wsId = vars.add(this.workspaceId.name, '::uuid')
|
||||
res.push(
|
||||
`(SELECT jsonb_agg(assoc.*)
|
||||
FROM ${translateDomain(this.hierarchy.getDomain(_class))} AS assoc
|
||||
FROM ${tagetDomain} AS assoc
|
||||
JOIN ${translateDomain(DOMAIN_RELATION)} as relation
|
||||
ON relation."${keyB}" = assoc."_id"
|
||||
AND relation."workspaceId" = ${wsId}
|
||||
WHERE relation."${keyA}" = ${translateDomain(baseDomain)}."_id"
|
||||
AND assoc."workspaceId" = ${wsId}) AS assoc_${association[0]}`
|
||||
AND assoc."workspaceId" = ${wsId}) AS assoc_${tagetDomain}_${association[0]}`
|
||||
)
|
||||
}
|
||||
return res
|
||||
|
Loading…
Reference in New Issue
Block a user