IOInterrupt
IOInterrupt

Reputation: 539

Unable to left join on multiple tables with PhalconPHP's createBuilder?

Maybe I am doing something wrong here, but I am unable to join on multiple tables when using createBuilder(). Here is an example query.

$test = $this->modelsManager->createBuilder()
        ->from('TABLE1')
        ->leftJoin('TABLE2', 'TABLE1.id = TABLE2.table_one_id')
        ->leftJoin'TABLE3', 'TABLE3.id = TABLE2.table_three_id')
        ->where('TABLE1.id = :id:', array('id' => $id))
        ->groupBy(array('TABLE1.id'))
        ->getQuery()
        ->execute();

There error indicates that the SQL query is probably not being generated correctly by the framework, but I could very well be doing something wrong. It appears that no space is being added before the additional LEFT join.

Unknown column 'TABLE2.table_one_idLEFT' in 'on clause''

Any insight would be greatly appreciated.

Upvotes: 0

Views: 4200

Answers (1)

Iustinian
Iustinian

Reputation: 69

You will need to add a space at the end of first join condition:

$test = $this->modelsManager->createBuilder()
        ->from('TABLE1')
        ->leftJoin('TABLE2', 'TABLE1.id = TABLE2.table_one_id ')
        ->leftJoin('TABLE3', 'TABLE3.id = TABLE2.table_three_id')
        ->where('TABLE1.id = :id:', array('id' => $id))
        ->groupBy(array('TABLE1.id'))
        ->getQuery()
        ->execute();

Upvotes: 2

Related Questions