I have a many to many relationships in my project (user_role, grades, user_role_grades). But I also have a requirement not to delete any data from my db. So, I have add a status column to the table, that connecting 2 tables to create many to many relationship. Now I want on
我的项目中有很多关系(user_role,grade,user_role_grades)。但我也要求不要从我的数据库中删除任何数据。所以,我在表中添加了一个状态列,连接2个表以创建多对多的关系。现在我想要
$userRole->getGrades()
get only those records, that in unite table (user_role_grades) has no status "0". For those, I`m trying to use doctrine sql filter.
只获取那些记录,在unite table(user_role_grades)中没有状态“0”。对于那些,我试图使用doctrine sql过滤器。
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 Bis\DefaultBundle\Entity\UserRoleGrade entity. Have anyone any ideas?
因此,它被称为Bis \ DefaultBundle \ Entity \ UserRole,但不适用于Bis \ DefaultBundle \ Entity \ UserRoleGrade实体。有什么想法吗?
Or may be you have some other ideas, how I can do that?
或者你可能有其他一些想法,我怎么能这样做?
1 个解决方案
#1
1
I don't think this is possible, because it appends directly SQL. Even if you'd try sth like SQL injection:
我不认为这是可能的,因为它直接附加SQL。即使你尝试像SQL注入一样:
return $targetTableAlias . '.status != 0)) LEFT join the_other_table ON '
. $targetTableAlias . '.grades HAVING the_other_table.status = 0 ((';
It would probably collapse on statement like (())
它可能会在像(())这样的语句上崩溃
#1
1
I don't think this is possible, because it appends directly SQL. Even if you'd try sth like SQL injection:
我不认为这是可能的,因为它直接附加SQL。即使你尝试像SQL注入一样:
return $targetTableAlias . '.status != 0)) LEFT join the_other_table ON '
. $targetTableAlias . '.grades HAVING the_other_table.status = 0 ((';
It would probably collapse on statement like (())
它可能会在像(())这样的语句上崩溃