This topic contains 4 replies, has 2 voices, and was last updated by Hiro 9 years, 7 months ago.
- Topic
I have noticed Attachment data is left out when deleting Entity record using Attachment feature.
So I started creating this helper function so that I can just call it from deleteAction() in REST API Controller Class:
12345678910111213141516171819202122232425262728293031323334/*** Delete Attachment attached to Entity by Entity Id** @param string $entityName* @param string $entityId*/public function deleteAttachment($entityName, $entityId) {$doctrine = $this->getDoctrine();$em = $doctrine->getManager();/* Custom method to get single Entity record */$entity = $this->getEntityBy($entityName, $entityId);// I am not sure if I need this to get the dynamic field name$entityClass = get_class($entity);$repository = $doctrine->getRepository('OroAttachmentBundle:Attachment');/*** I am thinking there must be a function to get this dynamic field name* as this variable cannot be a literal value here*/$fieldName = 'acme_a1234567';$attachments = $repository->findBy(array($fieldName => $entityId));foreach ($attachments as $attachment) {$em->remove($attachment);}$em->flush();}One thing I cannot figure is about how we can know the extended field name in code.
Please let me know if there is already the deletion method somewhere.
I have found deleteAction() in Oro\Bundle\AttachmentBundle\Controller\Api\Rest, but the parameter is the Id for the attachment, not Entity Id so.
The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.