triggerBeforeFind() public method

Will not trigger more than once, and only for select queries.
public triggerBeforeFind ( ) : void
return void
Example #1
0
 /**
  * Cake\ORM\Query::triggerBeforeFind overwritten to add the condition `deleted IS NULL` to every find request
  * in order not to return soft deleted records.
  * If the query contains the option `withDeleted` the condition `deleted IS NULL` is not applied.
  */
 public function triggerBeforeFind()
 {
     if (!$this->_beforeFindFired && $this->_type === 'select') {
         parent::triggerBeforeFind();
         $aliasedField = $this->repository()->aliasField($this->repository()->getSoftDeleteField());
         if (!is_array($this->getOptions()) || !in_array('withDeleted', $this->getOptions())) {
             $this->andWhere($aliasedField . ' = 1');
         }
     }
 }
Example #2
0
 /**
  * Triggers beforeFind on the target table for the query this association is
  * attaching to
  *
  * @param \Cake\ORM\Query $query the query this association is attaching itself to
  * @return void
  */
 protected function _dispatchBeforeFind($query)
 {
     $query->triggerBeforeFind();
 }