From 005b5a313dee5f73010225e906b307fe05912388 Mon Sep 17 00:00:00 2001 From: jack zhang <1098626505@qq.com> Date: Fri, 29 Mar 2024 15:59:41 +0800 Subject: [PATCH] fix: association parent request (#3865) * fix: association parent request * fix: bug --- .../data-block/DataBlockRequestProvider.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core/client/src/data-source/data-block/DataBlockRequestProvider.tsx b/packages/core/client/src/data-source/data-block/DataBlockRequestProvider.tsx index c8d361d61..9af56e19b 100644 --- a/packages/core/client/src/data-source/data-block/DataBlockRequestProvider.tsx +++ b/packages/core/client/src/data-source/data-block/DataBlockRequestProvider.tsx @@ -7,6 +7,7 @@ import { AllDataBlockProps, useDataBlockProps } from './DataBlockProvider'; import { useDataBlockResource } from './DataBlockResourceProvider'; import { useDataSourceHeaders } from '../utils'; import { useDataLoadingMode } from '../../modules/blocks/data-blocks/details-multi/setDataLoadingModeSettingsItem'; +import { useCollection, useCollectionManager } from '../collection'; export const BlockRequestContext = createContext>(null); BlockRequestContext.displayName = 'BlockRequestContext'; @@ -55,6 +56,7 @@ function useCurrentRequest(options: Omit) { function useParentRequest(options: Omit) { const { sourceId, association, parentRecord } = options; const api = useAPIClient(); + const cm = useCollectionManager(); const dataBlockProps = useDataBlockProps(); const headers = useDataSourceHeaders(dataBlockProps.dataSource); return useRequest( @@ -63,8 +65,12 @@ function useParentRequest(options: Omit) { if (!association) return Promise.resolve({ data: undefined }); // "association": "Collection.Field" const arr = association.split('.'); - // :get/ - const url = `${arr[0]}:get/${sourceId}`; + const field = cm.getCollectionField(association); + const isM2O = field.interface === 'm2o'; + const filterTargetKey = cm.getCollection(arr[0]).getOption('filterTargetKey'); + const filterKey = isM2O ? filterTargetKey : field.sourceKey; + // :get?filter[filterKey]=sourceId + const url = `${arr[0]}:get?filter[${filterKey}]=${sourceId}`; const res = await api.request({ url, headers }); return res.data; }, @@ -88,6 +94,7 @@ export const BlockRequestProvider: FC = ({ children }) => { requestOptions, requestService, } = props; + const currentRequest = useCurrentRequest<{ data: any }>({ action, sourceId,