Skip to content

Commit 7c39087

Browse files
Fixed bug with loading selected related model records in AutoForm HasMany inputs in framework version 1.3
1 parent fce894e commit 7c39087

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gadgetinc/react": patch
3+
---
4+
5+
Fixed bug with loading selected related model records in AutoForm HasMany inputs in framework version 1.3

packages/react/cypress/component/auto/form/PolarisAutoHasManyInput.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe("PolarisAutoHasManyInput", () => {
6868
url: `${api.connection.endpoint}?operation=gizmos`,
6969
},
7070
(req) => {
71-
const queryIsForSelectedRecords = get(req.body.variables, "filter.widget.equals") === "42";
71+
const queryIsForSelectedRecords = get(req.body.variables, "filter.widgetId.equals") === "42";
7272

7373
req.reply({
7474
data: {

packages/react/src/auto/hooks/useRelatedModelOptions.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,13 @@ export const useLinkedParentModelRelatedModelRecords = (props: {
186186
);
187187
}
188188

189+
const filterField = `${inverseFieldApiIdentifier}Id`; // Filter on the `Id` suffixed inverse field for compatibility before and after framework version v1.3
190+
189191
const [{ data: selectedRecords, fetching: fetchingSelected, error: fetchSelectedRecordError }] = useFindMany(relatedModelManager as any, {
190192
pause: !currentRecordId || fetchingCurrentRecord, // HasOne/HasMany need the current record to query the inverse field in the related model
191193

192194
first: selectedRecordsToLoadCount, // Many records can point to the current record in hasOne/hasMany
193-
filter: { [inverseFieldApiIdentifier]: { equals: currentRecordId } }, // Filter by the inverse field belongsTo field value
195+
filter: { [filterField]: { equals: currentRecordId } }, // Filter by the inverse field belongsTo field value
194196
});
195197

196198
return {

0 commit comments

Comments
 (0)