2015-01-09 35 views
5

Ho un'applicazione multi tenant e sto usando il Doctrine Filters per filtrare il mio SQL dal client.Doctrine Filter in WHERE clausola invece SINISTRA JOIN

Così, quando voglio un elenco del mio cliente Progetti ho solo bisogno di fare un "getAll" e il filtro aggiungerà automaticamente il codice SQL sulla clausola WHERE, come questo:

SELECT * 
FROM projects p 
WHERE p.client_id = 1 #(appended by the filter) 

mio il problema è quando voglio ad esempio il ProjectMembers. Il filtro aggiungerà l'SQL per il LEFT JOIN, non alla clausola WHERE, rendendo inutile il filtro perché restituirà tutti i ProjectMembers, anche loro non sono da parte del cliente 1.

SELECT * 
FROM projects p 
LEFT JOIN project_members pm ON pm.project_id = p.id 
AND p.client_id = 1 #(appended by the filter) 

Questo è il mio addFilterConstrait

public function addFilterConstraint(ClassMetaData $targetEntity, $targetTableAlias) 
{ 
    $class = $targetEntity->getName(); 

    if (array_key_exists($class, $this->disabled) && $this->disabled[$class] === true) { 
     return ''; 
    } elseif (array_key_exists($targetEntity->rootEntityName, $this->disabled) && $this->disabled[$targetEntity->rootEntityName] === true) { 
      return ''; 
    } 

    $config = $this->getFilterConfig($targetEntity->getReflectionClass()); 

    if (!isset($config['clientFilter']) || !$config['clientFilter']) { 
     return ''; 
    } 

    return $targetTableAlias. '.' . $config['columnName'] . ' = ' . $this->getParameter('client'); // getParameter applies quoting automatically 
} 

Tutte le idee come posso risolvere questo, aggiungere il filtro alla dove al posto di LEFT JOIN?

+0

Qualcosa non si aggiunge qui. La tua seconda query non è valida DQL. Perché dovresti fare "SELECT * FROM projects p ... LEFT JOIN projects p'? Sei sicuro di aver costruito correttamente il tuo join? Normalmente il formato DQL sarebbe 'SELECT * FROM projects p LEFT JOIN p.projectMembers pm ...'. Dove e come viene costruito questo DQL? Questa domanda proviene dal tuo profilo? – sjagr

+0

Il DQL è corretto, ho pubblicato SQL per essere più facile da capire. – costa

+0

Eri corretto, ho appena modificato la SINISTRA SINISTRA – costa

risposta

-2

Prova questo:

SELECT * FROM table1, table2 WHERE table1.id = table2.id 

questo potrebbe risolvere il tuo problema.