Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Api-platform filter annotation for Many To Many

$
0
0

I've follow the implementation of filters with annotation to load only the sources concern for one user. Very usefull, work properly.

https://api-platform.com/docs/core/filters/#using-doctrine-filters

BUT : I want to do the same in my entity with an ManyToMany relationship and not ManyToOne like this :

<?phpnamespace App\Entity;use ApiPlatform\Core\Annotation\ApiResource;use ApiPlatform\Core\Annotation\ApiSubresource;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Validator\Constraints as Assert;use Doctrine\Common\Collections\ArrayCollection;use App\Annotation\UserAware;/** * * @ApiResource(routePrefix="/api") * @ORM\Entity * @ORM\Table(name="albums") * @UserAware(userFieldName="user_owner") * @UserAware(userFieldName="album_access_user") */class Album{    //...    /**     * @ORM\ManyToOne(targetEntity="User")     * @ORM\JoinColumn(nullable=false, name="user_owner", referencedColumnName="id")    */    public $userOwner;    /**     * @ORM\ManyToMany(targetEntity="User", inversedBy="albums")     * @ORM\JoinTable(name="album_access")     * @ORM\JoinTable(     *  name="album_access",     *  joinColumns={     *      @ORM\JoinColumn(name="album_access_album", referencedColumnName="id")     *  },     *  inverseJoinColumns={     *      @ORM\JoinColumn(name="album_access_user", referencedColumnName="id")     *  }     * )    */    private $accesses;    //...}

AS there is a JoinTable now and not just a JoinColum, i have to adapt the UserFilterConfigurator.php Event but i've no idea how to do that to give him the table and not juste the column...

Here is the logic error i get because i ask for the Entity Table and not the Join Table for now :

An exception occurred while executing 'SELECT DISTINCT o0_.id AS id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_.album_access_user = '4') ORDER BY o0_.id ASC LIMIT 30':\n\nSQLSTATE[42703]: Undefined column: 7 ERROR:  column o0_.album_access_user does not exist\nLINE 1: ...id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_...

How can I get that for ManyToMany <=> how can i pass the good (join)table + (join) column ??


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>