Cake\ORM\Query::triggerBeforeFind PHP Method

triggerBeforeFind() public method

Will not trigger more than once, and only for select queries.
public triggerBeforeFind ( ) : void
return void
    public function triggerBeforeFind()
    {
        if (!$this->_beforeFindFired && $this->_type === 'select') {
            $table = $this->repository();
            $this->_beforeFindFired = true;
            $table->dispatchEvent('Model.beforeFind', [$this, new ArrayObject($this->_options), !$this->eagerLoaded()]);
        }
    }

Usage Example

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');
         }
     }
 }
All Usage Examples Of Cake\ORM\Query::triggerBeforeFind