/**
  * @param bool $populateJunctions
  * @return ActiveQuery
  * @throws ErrorException
  */
 public function getNavItems($populateJunctions = false)
 {
     if (!$this instanceof ActiveRecord) {
         throw new ErrorException(__CLASS__ . ' is not instance of yii\\db\\ActiveRecord.');
     }
     /** @var ActiveRecord $this */
     /** @var ActiveQuery $query */
     $query = $this->hasMany(Item::className(), ['name' => 'child_name'])->via('navItemsChild');
     if ($populateJunctions === true) {
         $query->innerJoinWith(['parentItemsJunctions' => function (ActiveQuery $query) {
             $query->from(['parentItemJunction' => ItemChild::tableName()]);
         }]);
     } else {
         $query->innerJoin(ItemChild::tableName() . ' `parentItemJunction`', '`parentItemJunction`.`child_name` = ' . Item::tableName() . '.`name`');
     }
     $query->joinWith(['childItems' => function (ActiveQuery $query) {
         $query->from(['childItem' => Item::tableName()]);
     }]);
     return $query->orderBy('parentItemJunction.weight');
 }
Пример #2
0
 public function getChildItemsJunctions()
 {
     return $this->hasMany(ItemChild::className(), ['parent_name' => 'name']);
 }
Пример #3
0
 public function getItemsJunctions()
 {
     return $this->hasMany(ItemChild::className(), ['nav_id' => 'id']);
 }