/**
  * Unlink every associated record, method will return amount of affected rows. Method will
  * unlink only records matched WHERE_PIVOT by default. Set wherePivot to false to unlink every
  * record.
  *
  * @param bool $wherePivot Use conditions specified by WHERE_PIVOT, enabled by default.
  * @return int
  */
 public function unlinkAll($wherePivot = true)
 {
     $innerKey = $this->definition[RecordEntity::INNER_KEY];
     $query = [$this->definition[RecordEntity::THOUGHT_INNER_KEY] => $this->parent->getField($innerKey)];
     if ($wherePivot && !empty($this->definition[RecordEntity::WHERE_PIVOT])) {
         $query = $query + $this->definition[RecordEntity::WHERE_PIVOT];
     }
     return $this->pivotTable()->delete($query)->run();
 }
示例#2
0
 /**
  * Load relation data based on created selector.
  *
  * @return array|null
  */
 protected function loadData()
 {
     if (!$this->parent->isLoaded()) {
         //Nothing to load for unloaded parents
         return null;
     }
     $this->loaded = true;
     if (static::MULTIPLE) {
         return $this->data = $this->createSelector()->fetchData();
     }
     $data = $this->createSelector()->fetchData();
     if (isset($data[0])) {
         return $this->data = $data[0];
     }
     return null;
 }
示例#3
0
 /**
  * Loadable when parent is loaded as well.
  *
  * @return bool
  */
 protected function isLoadable()
 {
     return $this->parent->isLoaded();
 }