Details
Description
Here an example of a simple QueryBuilder :
$queryBuilder = $entityManager->createQueryBuilder();
$queryBuilder->select ( "player, options" );
$queryBuilder->from ( "Player_Model_Entity_Player", "player");
$queryBuilder->where ("player.idPlayer = 12");
$queryBuilder->leftJoin ("player.options", "options", "WITH", "options.enabled = :enabled");
$queryBuilder->setParameter ("enabled", 1);
OptionA & OptionB & OptionC three entities.
User case :
- OptionA.enabled = 1 & OptionB.enabled = 1 & OptionC.enabled = 1 : OK - All options are return.
- OptionA.enabled = 1 & OptionB.enabled = 0 & OptionC.enabled = 0 : OK - only optionA is return.
- OptionA.enabled = 1 & OptionB.enabled = 0 & OptionC.enabled = 1 : OK - only optionA & optionC is return.
- OptionA.enabled = 0 & OptionB.enabled = 1 & OptionC.enabled = 1 : KO - no option return.
- OptionA.enabled = 0 & OptionB.enabled = 0 & OptionC.enabled = 0 : OK - no option return.
I have test on OneToMany configuration and I have not problem. The problem only appear with ManyToMany relationships.
The problem seems to be on hydratation. The data return on SQL command seems to be correct.
I have made some other search about it.
On the queryBuilder described above, I was using getSingleResult / getResult.
When I'm using getScalarResult I can see data of every options.
Here the scalar result :
array(3) { [0]=> array(21) { ["player_id"]=> int(2) ["options_id"]=> NULL ["options_enabled"]=> NULL } [1]=> array(21) { ["player_id"]=> int(2) ["options_id"]=> int(2) ["options_enabled"]=> bool(true) } [2]=> array(21) { ["player_id"]=> int(2) ["options_id"]=> int(4) ["options_enabled"]=> bool(true) } }Do you have any clue ?