I am using the api-platform framework with a MySQL backend. I am getting errors when API clients use the POST end point to submit data if there is already an entry in the database.
Currently I am using a PRE_WRITE EventSubscriberInterface class to find the original database entry and delete it. However this seems incredable inefficient compared to a simple update action.
I am able to update the existing database entry, but then I'm unable to remove/stop the POST'd an item from being executed.
Is there a way around this? Ether to change the INSERT action to an ...ON DUPLICATE... or to simple stop the data the user post'd from being saved to the database?
You can also use the property "UniqueEntity" to set what's make your entity unique.
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity("slug")
*/
class Article
{
//...
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
}