As an addition. If I try to refine the expression a bit.
Tile::where('id', '224718')
->with(['player_unit_groups.player_units'
=> function($query)
{
$query->join('units', 'units.id', 'player_units.unit_id');
}])->first();
I can get a nicer result.
=> App\Tile {#824
tile: 2218,
player_unit_groups: Illuminate\Database\Eloquent\Collection {#851
all: [
App\PlayerUnitGroup {#829
id: 1,
tile_id: 224718,
player_id: 1,
public_uuid: "a6b01d5f-cef7-4438-b476-de38a78ce695",
name: "",
created_at: "2017-11-13 13:26:53",
updated_at: "2017-11-13 13:26:53",
player_units: Illuminate\Database\Eloquent\Collection {#828
all: [
App\PlayerUnit {#848
id: 1,
unit_id: 1,
player_unit_group_id: 1,
count: 50,
public_uuid: "9bcd7281-1d5d-4fc1-af3d-1c0f3df5dafe",
created_at: "2017-11-13 13:25:13",
updated_at: "2017-11-13 13:25:13",
name: "Unit I",
defence: 3,
attack: 5,
type: 0,
},
],
},
},
],
},
}
But if I try to do a join against the unit_events table, I end up empty. And I have checked and made sure that there's a corresponding row in the database.
Tile::where('id', '224718')
->with(['player_unit_groups.player_units'
=> function($query)
{
$query->join('units', 'units.id', 'player_units.unit_id');
},
'player_unit_groups'
=> function($query)
{
$query->join(
'unit_events',
'player_unit_groups.id',
'unit_events.player_unit_group_id');
}])->first();
=> App\Tile {#865
tile: 2218,
player_unit_groups: Illuminate\Database\Eloquent\Collection {#874
all: [],
},
}
So perhaps my problem is in the join? Or maybe that is to be seen as an illegal/bad way of trying to solve it? In the case above I'm just trying to make the join work to see that at least the relationship works there. And if I can get that working I will try to negate that.