diff --git a/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx b/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx index 817b3e503ae..42caaf389e2 100644 --- a/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx +++ b/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx @@ -436,7 +436,7 @@ describe('', () => { ).toEqual([defaultProps.reference, [6]]); }); - it('should call crudGetMany with empty list when already fetched input value changes', () => { + it('should not call crudGetMany when already fetched input value changes', () => { const crudGetMany = jest.fn(); const wrapper = shallow( ', () => { /> ); expect( - crudGetMany.mock.calls[crudGetMany.mock.calls.length - 1] + crudGetMany.mock.calls[0] ).toEqual([defaultProps.reference, [5, 6]]); wrapper.setProps({ input: { value: [6] } }); expect( - crudGetMany.mock.calls[crudGetMany.mock.calls.length - 1] - ).toEqual([defaultProps.reference, []]); + crudGetMany.mock.calls.length + ).toEqual(1); }); - it('should call crudGetOne and crudGetMatching when record changes', () => { + it('should only call crudGetOne and not crudGetMatching when only the record changes', () => { const crudGetMany = jest.fn(); const crudGetMatching = jest.fn(); const wrapper = shallow( @@ -471,6 +471,6 @@ describe('', () => { assert.equal(crudGetMany.mock.calls.length, 1); wrapper.setProps({ record: { id: 1 } }); assert.equal(crudGetMatching.mock.calls.length, 2); - assert.equal(crudGetMany.mock.calls.length, 2); + assert.equal(crudGetMany.mock.calls.length, 1); }); }); diff --git a/packages/ra-core/src/controller/input/ReferenceArrayInputController.tsx b/packages/ra-core/src/controller/input/ReferenceArrayInputController.tsx index 7c4edbcfd7c..6d03b2a3fa3 100644 --- a/packages/ra-core/src/controller/input/ReferenceArrayInputController.tsx +++ b/packages/ra-core/src/controller/input/ReferenceArrayInputController.tsx @@ -139,9 +139,7 @@ interface EnhancedProps { * * */ -export class UnconnectedReferenceArrayInputController extends Component< - Props & EnhancedProps -> { +export class UnconnectedReferenceArrayInputController extends Component { public static defaultProps = { allowEmpty: false, filter: {}, @@ -237,7 +235,7 @@ export class UnconnectedReferenceArrayInputController extends Component< const idsToFetch = isInitialCall ? ids : difference(ids, this.props.input.value); - crudGetMany(reference, idsToFetch); + if (idsToFetch.length) crudGetMany(reference, idsToFetch); } };