Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make sure the inner join with the junction table happens first
  • Loading branch information
lorenzo committed Sep 11, 2014
1 parent 571fc63 commit 708fb08
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/ORM/Association/BelongsToMany.php
Expand Up @@ -873,7 +873,21 @@ protected function _collectJointEntities($sourceEntity, $targetEntities) {
*/
protected function _buildQuery($options) {
$name = $this->_junctionAssociationName();
return $this->_buildBaseQuery($options)->matching($name);
$query = $this->_buildBaseQuery($options);
$joins = $query->join() ?: [];
$keys = $this->_linkField($options);

$matching = [
$name => [
'table' => $this->junction()->table(),
'conditions' => $keys,
'type' => 'INNER'
]
];

$joins = $matching + $joins;
$query->join($joins, [], true)->matching($name);
return $query;
}

/**
Expand Down

0 comments on commit 708fb08

Please sign in to comment.