Home » Php » php – Get multiple objects of multiple entities by paramConverter / JMS

php – Get multiple objects of multiple entities by paramConverter / JMS

Posted by: admin February 25, 2020 Leave a comment

Questions:

In my api have 3 parameters: warehouse_ids[], hardware_ids[] & color_names[] So my controller code kind of

     * @Rest\QueryParam(name="warehouse_ids", nullable=true, description="List of warehouse ids")
     * @Rest\QueryParam(name="hardware_ids", nullable=true, description="List of hardware ids")
     * @Rest\QueryParam(name="color_names", nullable=true, description="List of color names")
     *
     * @ParamConverter("context", converter="fos_rest.query_string", options={"validate": true})
     *
     * @param HardwareQuantityApiContext $context

And my HardwareQuantityApiContext is kind of

class HardwareQuantityApiContext
{
    protected $warehouse_ids;

    protected $hardware_ids;

    protected $color_names;
}

So its working fine. But now I want entity data instead of id list. So class looks like:

class HardwareQuantityApiContext
{
    /**
     * @JMS\Type("array<Entity\Warehouse>")
     * @Assert\Type("array")
     * @var Warehouse[]
     */
    protected $warehouses;

    .....
    protected $hardwares;

    protected $color_names;
}

But its returning empty array. It seems to me api parameter warehouse_ids not mapping properly. Can anyone have Idea?

How to&Answers: