0

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.

1 Answer 1

2

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();
1
  • Thanks for the suggestion, but I do believe the PhalconPHP developer fixed this issue in the 1.2.0 branch. Jun 25, 2013 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.