mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 23:57:32 +00:00
fix: error in CM when deleting components from DZ (#23002)
This commit is contained in:
parent
1f9d3b3bd8
commit
99934b46e6
@ -189,4 +189,38 @@ describe('removeOrphanMorphType', () => {
|
||||
expect(mockDb.connection).toHaveBeenCalledWith('another_table_with_component_type');
|
||||
expect(mockDb.connection).not.toHaveBeenCalledWith('table_without_component_type');
|
||||
});
|
||||
|
||||
it('should query the database when there is no target for component and entity join table', async () => {
|
||||
const mockMetadataMap = new Map([
|
||||
[
|
||||
'model1',
|
||||
{
|
||||
attributes: {
|
||||
someRelation: {
|
||||
type: 'relation',
|
||||
relation: 'morphToMany',
|
||||
joinTable: {
|
||||
name: 'countries_cmps',
|
||||
joinColumn: { name: 'entity_id', referencedColumn: 'id' },
|
||||
pivotColumns: ['entity_id', 'cmp_id', 'field', 'component_type'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
(mockDb.metadata.values as jest.Mock).mockReturnValue(mockMetadataMap.values());
|
||||
|
||||
mockDb.metadata.get = jest.fn().mockImplementation((type: string) => {
|
||||
if (type === 'validType') {
|
||||
return {}; // Simulate valid metadata
|
||||
}
|
||||
throw new Error('Metadata not found'); // Simulate missing metadata
|
||||
}) as jest.MockedFunction<typeof mockDb.metadata.get>;
|
||||
|
||||
await removeOrphanMorphType(mockDb, { pivot: PIVOT_COLUMN });
|
||||
|
||||
expect(mockDb.connection).toHaveBeenCalledWith('countries_cmps');
|
||||
});
|
||||
});
|
||||
|
||||
@ -16,7 +16,6 @@ const isMorphRelationWithPivot = (
|
||||
attribute.type === 'relation' &&
|
||||
'relation' in attribute &&
|
||||
'joinTable' in attribute &&
|
||||
'target' in attribute &&
|
||||
'name' in attribute.joinTable &&
|
||||
'pivotColumns' in attribute.joinTable &&
|
||||
attribute.joinTable.pivotColumns.includes(pivot)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user