Propel icon indicating copy to clipboard operation
Propel copied to clipboard

Unused CROSS JOIN when using column names

Open david0 opened this issue 10 years ago • 2 comments

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);
    }
//...

david0 avatar Jun 05 '14 18:06 david0

+1

aklinkert avatar Mar 23 '15 14:03 aklinkert

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.

lathspell avatar Jul 07 '17 09:07 lathspell