@@ -135,24 +135,32 @@ private function deleteByEntityConfig($entityConfig, $id = null)
135
135
$ schemaName = $ entityConfig ['schema ' ];
136
136
$ updateQuery = $ this ->updateQueryBuilder ->buildUpdateQueryBySchemaName ($ schemaName );
137
137
$ schema = $ this ->config ->getSchemaByName ($ schemaName );
138
- $ discriminatorField = $ schema ->getDiscriminatorConfigField ();
139
- $ discriminatorValue = $ discriminatorField ->getValue ($ entityConfig );
140
138
141
139
if (empty ($ id )) {
142
- $ updateQuery ->addDeleteCriteriaByField (
140
+ $ discriminatorField = $ schema ->getDiscriminatorConfigField ();
141
+ $ discriminatorValue = $ discriminatorField ->getValue ($ entityConfig );
142
+ $ updateQuery ->addDeleteCriteriaByConfigField (
143
143
$ discriminatorField ->getDocumentFieldName (),
144
144
$ discriminatorValue
145
145
);
146
- $ message = sprintf ('Removing of %s is completed successfully ' ,
147
- $ entityConfig ['class ' ]
148
- );
149
-
146
+ $ message = sprintf ('Removing of %s is completed successfully ' , $ entityConfig ['class ' ]);
150
147
} else {
148
+ $ entityClass = $ entityConfig ['class ' ];
149
+ $ repository = $ this ->em ->getRepository ($ entityClass );
150
+ $ entity = $ repository ->find ($ id );
151
+
152
+ if (!$ entity ) {
153
+ throw new EntityNotFoundException (
154
+ sprintf ('% with %s id is not found ' , $ entityClass , $ id )
155
+ );
156
+ }
157
+
151
158
$ updateQuery ->addDeleteCriteriaByUniqueFieldValue (
152
- sprintf ( ' %s-%s ' , $ discriminatorValue , $ id )
159
+ $ schema -> getDocumentUniqueField ()-> getValue ( $ entity , $ entityConfig )
153
160
);
161
+
154
162
$ message = sprintf ('Removing of %s with id %s is completed successfully ' ,
155
- $ entityConfig [ ' class ' ] ,
163
+ $ entityClass ,
156
164
$ id
157
165
);
158
166
0 commit comments