Fix o2m fetch when not grouping

This commit is contained in:
rijkvanzanten
2021-05-27 12:25:30 -04:00
parent 7a81340271
commit c16063f14b
3 changed files with 22 additions and 7 deletions

View File

@@ -58,7 +58,8 @@ export default async function runAST(
const { columnsToSelect, primaryKeyField, nestedCollectionNodes } = await parseCurrentLevel(
schema,
collection,
children
children,
query
);
// The actual knex query builder instance. This is a promise that resolves with the raw items from the db
@@ -101,7 +102,8 @@ export default async function runAST(
async function parseCurrentLevel(
schema: SchemaOverview,
collection: string,
children: (NestedCollectionNode | FieldNode)[]
children: (NestedCollectionNode | FieldNode)[],
query: Query
) {
const primaryKeyField = schema.collections[collection].primary;
const columnsInCollection = Object.keys(schema.collections[collection].fields);
@@ -133,10 +135,11 @@ async function parseCurrentLevel(
}
/**
* Always fetch primary key in case there's a nested relation that needs it
* Always fetch primary key in case there's a nested relation that needs it, but only if there's
* no aggregation / grouping going on
*/
const childrenContainRelational = children.some((child) => child.type !== 'field');
if (childrenContainRelational && columnsToSelectInternal.includes(primaryKeyField) === false) {
const hasAggregationOrGrouping = 'aggregate' in query || 'group' in query;
if (columnsToSelectInternal.includes(primaryKeyField) === false && hasAggregationOrGrouping === false) {
columnsToSelectInternal.push(primaryKeyField);
}

View File

@@ -377,7 +377,13 @@ export default defineComponent({
const pkField = relatedPrimaryKeyField.value.field;
const newValue = (props.value || []).map((item) => {
if (typeof item === 'object' && pkField in item && pkField in edits && item[pkField] === edits[pkField]) {
if (
item &&
typeof item === 'object' &&
pkField in item &&
pkField in edits &&
item[pkField] === edits[pkField]
) {
return edits;
}

View File

@@ -71,6 +71,7 @@ import { Permission } from '@/types';
import api from '@/api';
import { appRecommendedPermissions, appMinimalPermissions } from '../../app-permissions';
import { unexpectedError } from '@/utils/unexpected-error';
import { orderBy } from 'lodash';
export default defineComponent({
components: { PermissionsOverviewHeader, PermissionsOverviewRow },
@@ -97,7 +98,12 @@ export default defineComponent({
);
const systemCollections = computed(() =>
collectionsStore.state.collections.filter((collection) => collection.collection.startsWith('directus_') === true)
orderBy(
collectionsStore.state.collections.filter(
(collection) => collection.collection.startsWith('directus_') === true
),
'name'
)
);
const systemVisible = ref(false);