Anahkiasen/arrounded — pull request #13 by bramdevries (2014-12-11 09:10:17+00:00)
Title: Only retrieve data from related table when using a BelongsToMany

I was having a problem using the `find` method when using a `BelongsToMany` relationship. I would do the following in a controller:

```php
public function __construct(GamesRepository $repository)
{
$this->repository = $repository;
// I only want the games of the current users to be available
$this->repository->setItems(Auth::user()->student->games());
}
```

Then further down I'd do

```php
$game = $this->repository->find(1);
var_dump($game->id); // Would return 4
```

Turns out the following query is executed:

```sql
select * from `games` inner join `game_player` on `games`.`id` = `game_player`.`game_id` where `game_player`.`player_id` = 1 and `games`.`id` = '1'
```

Which returns the following result:

```sql
id company_id status actions_in_play actions_market created_at updated_at id game_id player_id score budget actions
1 2 invitation NULL NULL 2014-12-11 08:13:34 2014-12-11 08:13:34 7 4 4 0 40 NULL
```

What this PR does is check if the `$items` is an instance of `BelongsToMany` and if so it will select only the columns from the relation table, eg: `games.*`