Skip to content

Commit

Permalink
Remove temporary columns from results
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Dec 18, 2018
1 parent 30aab9b commit 1618a63
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Builder.php
Expand Up @@ -28,4 +28,33 @@ public function groupLimit($value, $column)

return $this;
}

/**
* Execute the query as a "select" statement.
*
* @param array $columns
* @return \Illuminate\Support\Collection
*/
public function get($columns = ['*'])
{
$results = parent::get($columns);

if (! $this->groupLimit) {
return $results;
}

$column = last(explode('.', $this->groupLimit['column']));

$keys = [
'laravel_row',
'@laravel_partition := '.$this->grammar->wrap($column),
'@laravel_partition := '.$this->grammar->wrap('pivot_'.$column),
];

foreach ($results as $result) {
unset($result->{$keys[0]}, $result->{$keys[1]}, $result->{$keys[2]});
}

return $results;
}
}
3 changes: 3 additions & 0 deletions tests/HasEagerLimitTest.php
Expand Up @@ -14,6 +14,8 @@ public function testHasOne()

$this->assertEquals(3, $users[0]->post->id);
$this->assertEquals(6, $users[1]->post->id);
$this->assertArrayNotHasKey('laravel_row', $users[0]->post);
$this->assertArrayNotHasKey('@laravel_partition := `user_id`', $users[0]->post);
}

public function testMorphOne()
Expand Down Expand Up @@ -54,6 +56,7 @@ public function testBelongsToMany()

$this->assertEquals([3, 2], $users[0]->roles->pluck('id')->all());
$this->assertEquals([6, 5], $users[1]->roles->pluck('id')->all());
$this->assertArrayNotHasKey('@laravel_partition := `pivot_user_id`', $users[0]->roles[0]);
}

public function testMorphToMany()
Expand Down

0 comments on commit 1618a63

Please sign in to comment.