Skip to content

Commit

Permalink
Fix for queries with attribute (fixes #260)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Jun 3, 2019
1 parent ee26af5 commit e234e20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ All notable changes to `laravel-query-builder` will be documented in this file
## 1.17.4 - 2019-06-03

- bugfix: `orderByRaw` is no longer being rejected as a sorting option (#258)
- bugfix: `addSelect` is no longer being replaced by the `?fields` parameter (#260)

## 1.17.3 - 2019-04-16

Expand Down
4 changes: 3 additions & 1 deletion src/Concerns/AddsFieldsToQuery.php
Expand Up @@ -110,7 +110,9 @@ protected function addModelFieldsToQuery()

$prependedFields = $this->prependFieldsWithTableName($modelFields, $modelTableName);

$this->select($prependedFields);
foreach ($prependedFields as $field) {
$this->addSelect($field);
}
}

protected function prependFieldsWithTableName(array $fields, string $tableName): array
Expand Down
18 changes: 17 additions & 1 deletion tests/ColumnTest.php
Expand Up @@ -20,7 +20,7 @@ public function setUp(): void
}

/** @test */
public function it_can_fetch_all_columns_if_none_is_given()
public function it_fetches_all_columns_if_none_are_given()
{
$queryBuilder = QueryBuilder::for(TestModel::class)->toSql();

Expand All @@ -42,4 +42,20 @@ public function it_can_fetch_only_required_columns()

$this->assertEquals($expected, $queryBuilder);
}

/** @test */
public function it_can_fetch_requested_columns_and_manually_added_selects()
{
$request = new Request([
'fields' => ['test_models' => 'name'],
]);

$queryBuilder = QueryBuilder::for(TestModel::class, $request)
->addSelect('email')
->toSql();

$expected = 'select "email", "test_models"."name" from "test_models"';

$this->assertEquals($expected, $queryBuilder);
}
}

0 comments on commit e234e20

Please sign in to comment.