diff --git a/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx b/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx
index 239fc254d7e..095343c9934 100644
--- a/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx
+++ b/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx
@@ -402,6 +402,33 @@ describe('', () => {
assert.equal(crudGetMany.mock.calls.length, 1);
});
+ it('should call crudGetMatching with replaced filter from outside', () => {
+ const crudGetMatching = jest.fn();
+ const crudGetMany = jest.fn();
+ const wrapper = shallow(
+
+ );
+ assert.equal(crudGetMatching.mock.calls.length, 1);
+ assert.equal(crudGetMany.mock.calls.length, 1);
+
+ wrapper.setProps({ filter: { foo: 'baz' } });
+ assert.deepEqual(crudGetMatching.mock.calls[1], [
+ 'tags',
+ 'posts@tag_ids',
+ { page: 1, perPage: 25 },
+ { field: 'id', order: 'DESC' },
+ { foo: 'baz' },
+ ]);
+ assert.equal(crudGetMany.mock.calls.length, 1);
+ });
+
it('should call crudGetMany when input value changes', () => {
const crudGetMany = jest.fn();
const wrapper = shallow(
diff --git a/packages/ra-core/src/controller/input/ReferenceArrayInputController.tsx b/packages/ra-core/src/controller/input/ReferenceArrayInputController.tsx
index f905cd66b54..bc520526095 100644
--- a/packages/ra-core/src/controller/input/ReferenceArrayInputController.tsx
+++ b/packages/ra-core/src/controller/input/ReferenceArrayInputController.tsx
@@ -258,8 +258,8 @@ export class UnconnectedReferenceArrayInputController extends Component<
pagination,
sort,
{
- ...filter,
...defaultFilter,
+ ...filter,
}
);
};