Propel
Propel copied to clipboard
Unused CROSS JOIN when using column names
We recently upgraded from Propel 1.6.5.
We noticed that some of our querys where running very long, because of an unnecessary CROSS JOIN
.
I tracked the problem down to some code where table aliases and column names (instead of phpNames) are involved. While this using the native column name is rather a bad practice, it would be better to maintain BC in this case.
Testcase:
//test/testsuite/runtime/query/ModelCriteriaTest.php
//...
public function testJoinWithNativeColumnName()
{
$c = new ModelCriteria('bookstore', 'Book');
$c->setModelAlias('b', true);
$c->where('b.title = ?', 'foo');
$c->join('b.Author a');
$c->where('a.first_name = ?', 'john');
$sql = "SELECT FROM `book` `b` INNER JOIN `author` `a` ON (b.author_id=a.id) WHERE b.title = :p1 AND a.first_name = :p2";
$params = array(
array('table' => 'book', 'column' => 'title', 'value' => 'foo'),
array('table' => 'author', 'column' => 'first_name', 'value' => 'john'),
);
$this->assertCriteriaTranslation($c, $sql, $params);
}
//...
+1
Very annoying indeed! Maybe related to https://github.com/propelorm/Propel/issues/861 As a workaround one can write
$c->where('`a`.first_name = ?', 'john');
The bug seems to be introduced in 1.6.8.