Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Doctrine2 "MEMBER OF" clause valid for a MySQL database?

The Doctrine2 DQL allows for the following SQL:

$query = $em->createQuery('SELECT u.id FROM CmsUser u WHERE :groupId MEMBER OF u.groups');
$query->setParameter('groupId', $group);
$ids = $query->getResult();

Is the MEMBER OF clause supported by a MySQL database?

Moreover, focusing on the previous example, is $group the id of the entity "Group" or is an instance of the "Group" entity itself?

like image 604
JeanValjean Avatar asked Jun 18 '12 09:06

JeanValjean


2 Answers

MEMBER OF is a pure ORM clause and has nothing to with the DBAL therefor it should work with any vendors.

MEMBER OF is supposed to accept an Entity but may accept an identifier too.

like image 78
Boris Guéry Avatar answered Oct 07 '22 22:10

Boris Guéry


I checked SQL generated with MEMBER OF clause:

SELECT *fields*
    FROM Page p0_ 
    WHERE 
       EXISTS (
          SELECT 1 
          FROM post_rubric p4_ 
          INNER JOIN Page p3_ 
             ON p4_.rubric_id = p3_.id 
          WHERE p4_.post_id = p0_.id AND p3_.id = ?
       )

Thats a way Doctrine translates MEMBER OF clause into SQL

like image 44
El' Avatar answered Oct 07 '22 22:10

El'