Relationship manager - Issues when using a union relation
I am building an application for tracking chess games.
I want to be able to look at a player and see all games they have played. However I need a union query as I do not know whether a Player was Player 1 or Player 2.
I have a model of Game which has the following properties:
'player_1_id', 'player_2_id', 'winner_id',
'player_1_id', 'player_2_id', 'winner_id',
Then I have a Player Model with the relation function of:
public function games() { return $this->hasMany(Game::class, 'player_1_id') ->union(Game::where('player_2_id', $this->id)); }
public function games() { return $this->hasMany(Game::class, 'player_1_id') ->union(Game::where('player_2_id', $this->id)); }
In tinker I am able to return all games that belong to a user.
I have created a relationship manager for the Player Resource but I get an error. By the looks of it Filament is adding an order by games.id.
I am not too sure how to proceed further to prevent this error. Can I tell filament not to have an order by?