phpmysqldoctrine-ormlaminas-api-tools

Unable to process entity but successful deletion in Doctrine using Apigility


I want to ask your ideas or solutions if why I came up with this response from my request.

I've been using Zend framework 2 and Apigility for API Calls.

This is the code I used to delete a certain id from the table Calendar Item. The id is the primary key of the table.

public function removeCalendarItem($id, $em)
{

    $item = $em->find('Admin\Entity\CalendarItem', $id);

    $em->remove($item);
    $em->flush();

    return $item->getDeletedAt()->format('c');
}

The id was successfully deleted in the database.

Id    data             deleted_at
34 |  test            | 2017-03-15 15:07:30 

I tried to do the request using the postman and it shows an error like this:

{
 "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
 "title": "Unprocessable Entity",
 "status": 422,
 "detail": "Unable to delete entity."
}

The table is Softdeleted.

I am looking forward to your assistance. I've been stucked on this for hours. Thanks a lot.


Solution

  • If modify your delete logic to 'return true' then the API response should render a HTTP 204 as expected.

    return true;