Doctrine sql filter application in many ways

I have many, many relationships in my project (user_role, grades, user_role_grades). But I also have a requirement not to delete data from my db. Thus, I add a status column to a table that joins 2 tables to create many, many relationships. Now i want on

$userRole->getGrades() 

get only those records that in the join table (user_role_grades) do not have the status "0". For those, I'm trying to use doctrine sql filter.

 namespace Bis\MpBundle\Filter; use \Doctrine\ORM\Mapping\ClassMetaData; class UserRoleGradeFilter extends \Doctrine\ORM\Query\Filter\SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if("Bis\DefaultBundle\Entity\UserRoleGrade" == $targetEntity->name){ return $targetTableAlias . '.status != 0'; } return ''; } } 

So, it is called for Bis \ DefaultBundle \ Entity \ UserRole, but not for the Bis \ DefaultBundle \ Entity \ UserRoleGrade object. Does anyone have any ideas?

Or maybe you have other ideas, how can I do this?

+4
source share
1 answer

I do not think this is possible because it directly joins SQL. Even if you try to use sth as an SQL injection:

 return $targetTableAlias . '.status != 0)) LEFT join the_other_table ON ' . $targetTableAlias . '.grades HAVING the_other_table.status = 0 (('; 

It will probably crash into an instruction like (())

+1
source

Source: https://habr.com/ru/post/1432248/


All Articles