src/ngrest/base/Api.php
public function actionRelationCall($arrayIndex, $id, $modelClass, $query = null)
    {
        $this->checkAccess('relation-call');
        
        $modelClass = base64_decode($modelClass);
        $model = $modelClass::findOne((int) $id);
        
        if (!$model) {
            throw new InvalidCallException("Unable to resolve relation call model.");
        }
        
        /** @var $relation \luya\admin\ngrest\base\NgRestRelationInterface */
        $relation = $model->getNgRestRelationByIndex($arrayIndex);

        if (!$relation) {
            throw new InvalidCallException("Unable to find the given ng rest relation for this index value.");
        }

        $find = $relation->getDataProvider();
        
        if ($find instanceof ActiveQuery && !$find->multiple) {
            throw new InvalidConfigException("The relation definition must be a hasMany() relation.");
        }
        
        if ($find instanceof ActiveQueryInterface) {
            $find->with($this->getWithRelation('relation-call'));
        }

        $this->appendPoolWhereCondition($find);

        $targetModel = Yii::createObject(['class' => $relation->getTargetModel()]);

        if ($query) {
            foreach ($targetModel->getNgRestPrimaryKey() as $pkName) {
                $searchQuery = $targetModel->ngRestFullQuerySearch($query)->select([$targetModel->tableName() . '.' . $pkName]);
                $find->andWhere(['in', $targetModel->tableName() . '.' . $pkName, $searchQuery]);
            }
        }

        return new ActiveDataProvider([
            'query' => $find,
            'pagination' => $this->pagination,
            'sort' => [
                'attributes' => $this->generateSortAttributes($targetModel->getNgRestConfig()),
            ]
        ]);
    }
public function actionRelationCall($arrayIndex, $id, $modelClass, $query = null)
    {
        $this->checkAccess('relation-call');
        
        $modelClass = base64_decode($modelClass);
        $model = $modelClass::findOne((int) $id);
        
        if (!$model) {
            throw new InvalidCallException("Unable to resolve relation call model.");
        }
        
        /** @var $relation \luya\admin\ngrest\base\NgRestRelationInterface */
        $relation = $model->getNgRestRelationByIndex($arrayIndex);

        if (!$relation) {
            throw new InvalidCallException("Unable to find the given ng rest relation for this index value.");
        }

        $find = $relation->getDataProvider();
        
        if ($find instanceof ActiveQuery && !$find->multiple) {
            throw new InvalidConfigException("The relation definition must be a hasMany() relation.");
        }
        
        if ($find instanceof ActiveQueryInterface) {
            $find->with($this->getWithRelation('relation-call'));
        }

        $this->appendPoolWhereCondition($find);

        $targetModel = Yii::createObject(['class' => $relation->getTargetModel()]);

        if ($query) {
            foreach ($targetModel->getNgRestPrimaryKey() as $pkName) {
                $searchQuery = $targetModel->ngRestFullQuerySearch($query)->select([$targetModel->tableName() . '.' . $pkName]);
                $find->andWhere(['in', $targetModel->tableName() . '.' . $pkName, $searchQuery]);
            }
        }

        return new ActiveDataProvider([
            'query' => $find,
            'pagination' => $this->pagination,
            'sort' => [
                'attributes' => $this->generateSortAttributes($targetModel->getNgRestConfig()),
            ]
        ]);
    }
public function actionRelationCall ( $ arrayIndex , $ id , $ modelClass , $ query = null ) { $ this -> checkAccess ( 'relation-call' ) ; $ modelClass = base64_decode ( $ modelClass ) ; $ model = $ modelClass :: findOne ( ( int ) $ id ) ; if ( ! $ model ) { throw new InvalidCallException ( "Unable to resolve relation call model." ) ; } /** @var $relation \luya\admin\ngrest\base\NgRestRelationInterface */ $ relation = $ model -> getNgRestRelationByIndex ( $ arrayIndex ) ; if ( ! $ relation ) { throw new InvalidCallException ( "Unable to find the given ng rest relation for this index value." ) ; } $ find = $ relation -> getDataProvider ( ) ; if ( $ find instanceof ActiveQuery && ! $ find -> multiple ) { throw new InvalidConfigException ( "The relation definition must be a hasMany() relation." ) ; } if ( $ find instanceof ActiveQueryInterface ) { $ find -> with ( $ this -> getWithRelation ( 'relation-call' ) ) ; } $ this -> appendPoolWhereCondition ( $ find ) ; $ targetModel = Yii :: createObject ( [ 'class' => $ relation -> getTargetModel ( ) ] ) ; if ( $ query ) { foreach ( $ targetModel -> getNgRestPrimaryKey ( ) as $ pkName ) { $ searchQuery = $ targetModel -> ngRestFullQuerySearch ( $ query ) -> select ( [ $ targetModel -> tableName ( ) . '.' . $ pkName ] ) ; $ find -> andWhere ( [ 'in' , $ targetModel -> tableName ( ) . '.' . $ pkName , $ searchQuery ] ) ; } } return new ActiveDataProvider ( [ 'query' => $ find , 'pagination' => $ this -> pagination , 'sort' => [ 'attributes' => $ this -> generateSortAttributes ( $ targetModel -> getNgRestConfig ( ) ) , ] ] ) ; }
Call the dataProvider for a foreign model.

@param mixed $arrayIndex
@param mixed $id
@param string $modelClass The name of the model where the ngRestRelation is defined.
@param string $query An optional query to filter the response for the given search term (since 2.0.0)
@throws InvalidCallException
@return \yii\data\ActiveDataProvider
Call the dataProvider for a foreign model .