I have defined the class CoreCase
/**
* @ORM\Entity(repositoryClass="App\Repository\CoreCaseRepository")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"Diesel" = "DieselCase", "Carloan" = "CarloanCase"})
* @ORM\HasLifecycleCallbacks()
*
*/
abstract class CoreCase
{
.
.
.
}
and two classes DieselCase and Carloan:
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
*/
class DieselCase extends CoreCase
{
.
.
.
}
/**
* @ORM\Entity(repositoryClass="App\Repository\CarloanCaseRepository")
* @ORM\HasLifecycleCallbacks()
*/
class CarloanCase extends CoreCase
{
.
.
.
}
In the action, I'm using the param converter
/**
* @Rest\Get("/case/carloan/{case}", requirements={"case" = "\d+"})
*
*/
public function getCarloanCase(CarloanCase $case)
{
.
.
.
}
It works for me, if I call the URL, with an existing CarloanCase, for example /case/carloan/201
If I call the URL with an id of a DieselCase, I expect a 404-error, but I get the 500-error
"message": "Argument 1 passed to App\Controller\Api\Cases\CarloanController::getCarloanCase() must be an instance of App\Entity\Cases\CarloanCase, instance of App\Entity\Cases\DieselCase given, called in /home/alexander/projects/lawbutler/vendor/symfony/http-kernel/HttpKernel.php on line 150",
BUT! If I remove (repositoryClass="App\Repository\CarloanCaseRepository")
from the Carloan annotation, it works correctly, and I get the expected 404-error.
Why is the behavior so strange? What can I do?