2015-05-24 4 views
5

मैं सिद्धांत फ़िल्टर का उपयोग करता हूं और हाल ही में देखा है कि कथन हटाने के लिए फ़िल्टर लागू नहीं किए गए हैं। मैंने प्रलेखन और Google के माध्यम से खोदने की कोशिश की है, लेकिन रहस्य अनसुलझा रहता है।क्या Doctrine2 कथन हटाने के लिए फ़िल्टर लागू करता है

उदाहरण के लिए मैं फिल्टर जो कंपनी इतना की तरह हर चयन क्वेरी के लिए उपयोगकर्ता जोड़ता है है:

$userRepo->find(12); 

और

चयन से संशोधित किया गया है .... उपयोगकर्ता t0 से कहां t0.id = 12

में

का चयन करें .... उपयोगकर्ता t0 से कहां t0.id = 12 और (t0.company_id = '6')

शांत, कि मैं क्या जरूरत है।

मुझे परेशान करता है कि हटाए गए बयानों को छूटा नहीं लगता है। क्या किसी को पता है कि यह डिफ़ॉल्ट सिद्धांत वास्तुकला है या मेरी कॉन्फ़िगरेशन गलत है?

फिल्टर

use Doctrine\ORM\Mapping\ClassMetaData; 
use Doctrine\ORM\Query\Filter\SQLFilter; 
use Doctrine\Common\Annotations\Reader; 

class CompanyAware extends SQLFilter 
{ 
    /** 
    * @var Reader 
    */ 
    protected $reader; 

    /** 
    * @param ClassMetaData $targetEntity 
    * @param string $targetTableAlias 
    * 
    * @return string 
    */ 
    public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) 
    { 
     $query = ''; 
     $ann = 'Mrok\\PortalBundle\\Annotation\\CompanyAware'; 
     $isAware = $this->reader->getClassAnnotation($targetEntity->getReflectionClass(), $ann); 

     if ($isAware) { 
      $id = $this->getParameter('id'); 
      $query = sprintf('%s.company_id = %s', $targetTableAlias, $id); 
     } 

     return $query; 
    } 

    public function setAnnotationReader(Reader $reader) 
    { 
     $this->reader = $reader; 
    } 
} 
+0

हम अपने एसक्यूएल फिल्टर देख सकते हैं? – Federkun

उत्तर

1

के रूप में सिद्धांत डेटा संग्रह स्थान हटाएं (आईडी) नहीं है या deleteBy (मापदंड) के रूप में एक अंतर्निहित, मैं तुम्हें या तो $ em-> दूर करने के लिए बात कर रहे हैं मान ($ इकाई); या डीक्यूएल। कोड को देखकर (नीचे देखें) न तो निकालें या कैस्केड एसक्यूएल निष्पादित करने से पहले फ़िल्टर लागू करें। दस्तावेज इंगित करता है कि फ़िल्टर को डीक्यूएल पर लागू किया जाना चाहिए।

http://doctrine-orm.readthedocs.org/en/latest/reference/filters.html

/** 
* Deletes a managed entity. 
* 
* The entity to delete must be managed and have a persistent identifier. 
* The deletion happens instantaneously. 
* 
* Subclasses may override this method to customize the semantics of entity deletion. 
* 
* @param object $entity The entity to delete. 
* 
* @return void 
*/ 
public function delete($entity) 
{ 
    $class  = $this->class; 
    $em   = $this->em; 

    $identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity); 
    $tableName = $this->quoteStrategy->getTableName($class, $this->platform); 
    $idColumns = $this->quoteStrategy->getIdentifierColumnNames($class, $this->platform); 
    $id   = array_combine($idColumns, $identifier); 
    $types  = array_map(function ($identifier) use ($class, $em) { 

     if (isset($class->fieldMappings[$identifier])) { 
      return $class->fieldMappings[$identifier]['type']; 
     } 

     $targetMapping = $em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']); 

     if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) { 
      return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; 
     } 

     if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) { 
      return $targetMapping->associationMappings[$targetMapping->identifier[0]]['type']; 
     } 

     throw ORMException::unrecognizedField($targetMapping->identifier[0]); 

    }, $class->identifier); 

    $this->deleteJoinTableRecords($identifier); 
    $this->conn->delete($tableName, $id, $types); 
} 

/** 
* @todo Add check for platform if it supports foreign keys/cascading. 
* 
* @param array $identifier 
* 
* @return void 
*/ 
protected function deleteJoinTableRecords($identifier) 
{ 
    foreach ($this->class->associationMappings as $mapping) { 
     if ($mapping['type'] !== ClassMetadata::MANY_TO_MANY) { 
      continue; 
     } 

     // @Todo this only covers scenarios with no inheritance or of the same level. Is there something 
     // like self-referential relationship between different levels of an inheritance hierarchy? I hope not! 
     $selfReferential = ($mapping['targetEntity'] == $mapping['sourceEntity']); 
     $class   = $this->class; 
     $association  = $mapping; 
     $otherColumns = array(); 
     $otherKeys  = array(); 
     $keys   = array(); 

     if (! $mapping['isOwningSide']) { 
      $class  = $this->em->getClassMetadata($mapping['targetEntity']); 
      $association = $class->associationMappings[$mapping['mappedBy']]; 
     } 

     $joinColumns = $mapping['isOwningSide'] 
      ? $association['joinTable']['joinColumns'] 
      : $association['joinTable']['inverseJoinColumns']; 


     if ($selfReferential) { 
      $otherColumns = (! $mapping['isOwningSide']) 
       ? $association['joinTable']['joinColumns'] 
       : $association['joinTable']['inverseJoinColumns']; 
     } 

     foreach ($joinColumns as $joinColumn) { 
      $keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); 
     } 

     foreach ($otherColumns as $joinColumn) { 
      $otherKeys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); 
     } 

     if (isset($mapping['isOnDeleteCascade'])) { 
      continue; 
     } 

     $joinTableName = $this->quoteStrategy->getJoinTableName($association, $this->class, $this->platform); 

     $this->conn->delete($joinTableName, array_combine($keys, $identifier)); 

     if ($selfReferential) { 
      $this->conn->delete($joinTableName, array_combine($otherKeys, $identifier)); 
     } 
    } 
} 
+0

"मुझे लगता है कि आप या तो $ em-> निकालें ($ इकाई) का जिक्र कर रहे हैं;" - हा करता हु – mrok

संबंधित मुद्दे