Filter on Join Table not possible

**Silverstripe Version: 4.2.1 **

**Question: It’s not possible to set a Filter on Join Table **

I upgraded a Project from SS3 to 4.2.1. When I filter on a join like this (in my Game.php):

$awayplayers = $this->players()->leftJoin("Team_players", "Team_players.playerID = Player.ID")->filter(array("Team_players.TeamID" => $this->team2ID));

I get an Error:
[Emergency] Uncaught InvalidArgumentException: Team_players is not a relation on model MYNAMESPACE\Player
In SS3 this was no Problem. In this particular case TeamID is not ambigeous so it works when I just use “TeamID” instead of “Team_players.TeamID”. But I have many similar joins like that.

My DataObjects loks like tis:

class Player extends DataObject {

	private static $table_name = 'Player';
	private static $singular_name = 'Spieler/Trainer';
	private static $plural_name = 'Spieler/Trainer';

	private static $belongs_many_many = array(
		'teams' => Team::class,
		'games' => Game::class
	);
}

class Team extends DataObject {

	private static $table_name = 'Team';
	private static $singular_name = Team::class;
	private static $plural_name = 'Teams';

	private static $has_one = array(
		'club' => Club::class
	);
	
	private static $default_sort = 'Team.season DESC'; 
		
	private static $many_many = array(
		'competitions' => Competition::class,
		'players' => Player::class
	);
}

class Game extends DataObject {
	private static $table_name = 'Game';
	private static $has_one = array (
		"competition" => Competition::class,
		"team1" => Team::class,
		"team2" => Team::class
	);
	private static $many_many = array (
		'players' => Player::class 
	);
	private static $many_many_extraFields = array (
		'players' => array (
			'playerIn' => 'Int',
			'playerOut' => 'Int',
			'reserve' => DBBoolean::class,
			'replacedPlayerID' => 'Int',
			'yellowCard' => DBBoolean::class,
			'yellowRedCard' => DBBoolean::class,
			'redCard' => DBBoolean::class,
			'minuteYellowCard' => 'Int',
			'minuteRedCard' => 'Int' 
		) 
	);

Maybe I’ve misunderstood what you’re after here, but can’t you get what you need just using the ORM?

Would:

$awayplayers = $this->team2()->players();

…not give you what you want? That’ll return all the players from team 2 in the current game.

Hi there,
$awayplayers = $this->team2()->players(); gives me the whole squad. But I only want the Players that are Part of the current Nomination. They are in $game->players() but these are all Players from both teams.
I can do something like this:

$homeTeamPlayers = $this->team1()->players()->getIDList();
$homeplayers = $this->players()->byIDs($homeTeamPlayers);

It has nothing to do with the join at all, I guess.
On an other place I have:

$games = Game::get();
...
$games =  $games->filter(array("Game.matchStart:GreaterThan" => date ( "Y-m-d H:i:00" )));

and I get Game is not a relation on model MYNAMESPACE\Game
It themes that table names in filters did not work at all anymore.
Also not if I join them with “AS”

$games->leftJoin("Competition", "C.ID = Game.competitionID", "C")
		->filter(array("C.URLSegment" => $competitionType))

=> C is not a relation on model MYNAMESPACE\Game