Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function createSelector()
 {
     if (empty($selector = parent::createSelector())) {
         return null;
     }
     if (empty($this->parent)) {
         //No need for where conditions
         return $selector;
     }
     //Mounting where conditions
     $this->mountConditions($selector);
     //Aggregated keys (example: all parent ids)
     if (empty($aggregatedKeys = $this->parent->aggregatedKeys($this->getReferenceKey()))) {
         //Nothing to postload, no parents
         return null;
     }
     //Adding condition
     $selector->where($this->getKey(RecordEntity::OUTER_KEY), 'IN', $aggregatedKeys);
     return $selector;
 }
 /**
  * {@inheritdoc}
  *
  * @param string $parentRole Helps ManyToMany relation to force record role for morphed
  *                           relations.
  */
 public function createSelector($parentRole = '')
 {
     if (empty($selector = parent::createSelector())) {
         return null;
     }
     //Pivot table joining (INNER in post selection)
     $pivotOuterKey = $this->getPivotKey(RecordEntity::THOUGHT_OUTER_KEY);
     $selector->innerJoin($this->pivotTable() . ' AS ' . $this->pivotAlias(), [$pivotOuterKey => $this->getKey(RecordEntity::OUTER_KEY)]);
     //Pivot table conditions
     $this->pivotConditions($selector, $parentRole);
     if (empty($this->parent)) {
         return $selector;
     }
     //Where and morph conditions
     $this->mountConditions($selector);
     if (empty($this->parent)) {
         //For Many-To-Many loader
         return $selector;
     }
     //Aggregated keys (example: all parent ids)
     if (empty($aggregatedKeys = $this->parent->aggregatedKeys($this->getReferenceKey()))) {
         //Nothing to postload, no parents
         return null;
     }
     //Adding condition
     $selector->where($this->getPivotKey(RecordEntity::THOUGHT_INNER_KEY), 'IN', new Parameter($aggregatedKeys));
     return $selector;
 }