/**
  * Method that fetches and deletes document-file manyToMany association record Entity.
  *
  * @param  string $id file id
  * @return bool
  */
 protected function _deleteFileAssociationRecord($id)
 {
     $query = $this->_fileStorageAssociation->find('all', ['conditions' => [$this->_fileStorageForeignKey => $id]]);
     $entity = $query->first();
     if (is_null($entity)) {
         return false;
     }
     return $this->_fileStorageAssociation->delete($entity);
 }
Ejemplo n.º 2
0
 /**
  * Proxies the finding operation to the target table's find method
  * and modifies the query accordingly based of this association
  * configuration.
  *
  * If your association includes conditions, the junction table will be
  * included in the query's contained associations.
  *
  * @param string|array $type the type of query to perform, if an array is passed,
  *   it will be interpreted as the `$options` parameter
  * @param array $options The options to for the find
  * @see \Cake\ORM\Table::find()
  * @return \Cake\ORM\Query
  */
 public function find($type = null, array $options = [])
 {
     $query = parent::find($type, $options);
     if (!$this->conditions()) {
         return $query;
     }
     $belongsTo = $this->junction()->association($this->target()->alias());
     $conditions = $belongsTo->_joinCondition(['foreignKey' => $this->foreignKey()]);
     return $this->_appendJunctionJoin($query, $conditions);
 }
Ejemplo n.º 3
0
 /**
  * Loads a list of belongs to many from ids.
  *
  * @param Association $assoc The association class for the belongsToMany association.
  * @param array $ids The list of ids to load.
  * @return array An array of entities.
  */
 protected function _loadBelongsToMany($assoc, $ids)
 {
     $target = $assoc->target();
     $primaryKey = (array) $target->primaryKey();
     $multi = count($primaryKey) > 1;
     if ($multi) {
         if (count(current($ids)) !== count($primaryKey)) {
             return [];
         }
         $filter = new TupleComparison($primaryKey, $ids, [], 'IN');
     } else {
         $filter = [$primaryKey[0] . ' IN' => $ids];
     }
     return $assoc->find()->where($filter)->toArray();
 }