|
5 | 5 | use insolita\fractal\exceptions\ValidationException;
|
6 | 6 | use insolita\fractal\providers\CursorActiveDataProvider;
|
7 | 7 | use insolita\fractal\providers\JsonApiActiveDataProvider;
|
8 |
| -use League\Fractal\TransformerAbstract; |
9 | 8 | use Yii;
|
10 | 9 | use yii\base\InvalidConfigException;
|
11 | 10 | use yii\db\ActiveQueryInterface;
|
12 |
| -use function array_intersect; |
13 |
| -use function array_merge; |
14 | 11 |
|
15 | 12 | /**
|
16 | 13 | * Handler for routes GET /resource
|
@@ -93,24 +90,6 @@ protected function prepareDataFilter($requestParams)
|
93 | 90 | return null;
|
94 | 91 | }
|
95 | 92 |
|
96 |
| - /** |
97 |
| - * Eager loading for included relations |
98 |
| - * @param \yii\db\ActiveQueryInterface|\yii\db\ActiveQuery $query |
99 |
| - * @return \yii\db\ActiveQueryInterface |
100 |
| - */ |
101 |
| - protected function prepareIncludeQuery(ActiveQueryInterface $query):ActiveQueryInterface |
102 |
| - { |
103 |
| - if (!$this->transformer instanceof TransformerAbstract) { |
104 |
| - return $query; |
105 |
| - } |
106 |
| - $defaultIncludes = $this->transformer->getDefaultIncludes(); |
107 |
| - $allowedIncludes = $this->transformer->getAvailableIncludes(); |
108 |
| - $requestedIncludes = $this->controller->manager->getRequestedIncludes(); |
109 |
| - $include = array_merge($defaultIncludes, array_intersect($allowedIncludes, $requestedIncludes)); |
110 |
| - //@TODO: ?validate if included relations existed ? |
111 |
| - return empty($include)? $query : $query->with($include); |
112 |
| - } |
113 |
| - |
114 | 93 | /**
|
115 | 94 | * Add condition for parent model restriction if needed
|
116 | 95 | * @param \yii\db\ActiveQueryInterface $query
|
@@ -148,9 +127,9 @@ protected function makeDataProvider()
|
148 | 127 |
|
149 | 128 | /* @var $modelClass \yii\db\BaseActiveRecord */
|
150 | 129 | $modelClass = $this->modelClass;
|
| 130 | + $query = $this->prepareParentQuery($modelClass::find()); |
| 131 | + $query = $this->prepareIncludeQuery($query); |
151 | 132 |
|
152 |
| - $query = $this->prepareIncludeQuery($modelClass::find()); |
153 |
| - $query = $this->prepareParentQuery($query); |
154 | 133 |
|
155 | 134 | if (!empty($filter)) {
|
156 | 135 | $query->andWhere($filter);
|
|
0 commit comments