|
174 | 174 | $queryBuilder->first()->relatedModels;
|
175 | 175 |
|
176 | 176 | $this->assertQueryLogContains('select `test_models`.`id` from `test_models`');
|
177 |
| - $this->assertQueryLogContains('select `name` from `related_models`'); |
| 177 | + $this->assertQueryLogContains('select `related_models`.`name` from `related_models`'); |
178 | 178 | });
|
179 | 179 |
|
180 | 180 | it('can fetch only requested string columns from an included model', function () {
|
|
197 | 197 | $queryBuilder->first()->relatedModels;
|
198 | 198 |
|
199 | 199 | $this->assertQueryLogContains('select `test_models`.`id` from `test_models`');
|
200 |
| - $this->assertQueryLogContains('select `name` from `related_models`'); |
| 200 | + $this->assertQueryLogContains('select `related_models`.`name` from `related_models`'); |
| 201 | +}); |
| 202 | + |
| 203 | +it('can fetch only requested string columns from an included belongs to many model', function () { |
| 204 | + TestModel::first()->relatedThroughPivotModels()->create([ |
| 205 | + 'name' => 'related', |
| 206 | + ]); |
| 207 | + |
| 208 | + $request = new Request([ |
| 209 | + 'fields' => 'id,related_through_pivot_models.id,related_through_pivot_models.name', |
| 210 | + 'include' => ['relatedThroughPivotModels'], |
| 211 | + ]); |
| 212 | + |
| 213 | + $queryBuilder = QueryBuilder::for(TestModel::class, $request) |
| 214 | + ->allowedFields('id', 'related_through_pivot_models.id', 'related_through_pivot_models.name') |
| 215 | + ->allowedIncludes('relatedThroughPivotModels'); |
| 216 | + |
| 217 | + DB::enableQueryLog(); |
| 218 | + |
| 219 | + $queryBuilder->first()->relatedThroughPivotModels; |
| 220 | + |
| 221 | + $this->assertQueryLogContains('select `test_models`.`id` from `test_models`'); |
| 222 | + $this->assertQueryLogContains('select `related_through_pivot_models`.`id`, `related_through_pivot_models`.`name`, `pivot_models`.`test_model_id` as `pivot_test_model_id`, `pivot_models`.`related_through_pivot_model_id` as `pivot_related_through_pivot_model_id` from `related_through_pivot_models` inner join `pivot_models` on `related_through_pivot_models`.`id` = `pivot_models`.`related_through_pivot_model_id` where `pivot_models`.`test_model_id` in ('); |
201 | 223 | });
|
202 | 224 |
|
203 | 225 | it('can fetch requested array columns from included models up to two levels deep', function () {
|
|
299 | 321 | $queryBuilder->first()->relatedModels;
|
300 | 322 |
|
301 | 323 | $this->assertQueryLogContains('select * from `test_models`');
|
302 |
| - $this->assertQueryLogContains('select `id`, `name` from `related_models`'); |
| 324 | + $this->assertQueryLogContains('select `related_models`.`id`, `related_models`.`name` from `related_models`'); |
303 | 325 | });
|
304 | 326 |
|
305 | 327 | it('wont use sketchy field requests', function () {
|
|
0 commit comments