与symfony3以多对多关系获取关联数据的语义错误

I have a simple app makes in symfony3. I try to fetch appropriate tags for my entities and I have a problem.

There is a part of my tag entity:

/**
 * Tag
 *
 * @ORM\Table(name="tag")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\TagRepository")
 */
class Tag
{
    .
    .
    .

    /**
     * @ORM\ManyToMany(targetEntity="Note", mappedBy="tags")
     */
    private $notes;

...and there is a part of note entity:

/**
 * Note
 *
 * @ORM\Table(name="note")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\NoteRepository")
 */
class Note
{
     .
     .
     .

    /**
     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="notes", cascade={"persist"})
     * @ORM\JoinTable(name="notes_tags")
     */
    private $tags;

In my repository class I call:

if(!empty($data['tags'])) {
    $query->andWhere('n.tags = :tag')->setParameter('tag', 6);
}

...then results is:

[Semantical Error] line 0, col 46 near 'tags = :tag ORDER': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.

I'm really new in Symfony 2 and Doctrine so I need your help.

I found a solution, I have to use MEMBER OF clause:

    if(!empty($data['tags'])) {
        $query->andWhere(':tag MEMBER OF n.tags')->setParameter('tag', $data['tags']);
    }

Firstly, IMHO you need change in class Note inversedBy to "notes". Also be sure your code looks like http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#many-to-many-bidirectional