We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon query builder join multiple data

Hello,

my bd!

my code:

      $application =  Cms\Models\Application::query()
           ->join("Cms\Models\Licence", 'Cms\Models\Application.id = licence.application_id','licence')
           ->join("Cms\Models\Paiement", 'paiement.id = licence.paiement_id','paiement')

           ->columns(
               array(
                   'Cms\Models\Application.id',
                   'Cms\Models\Application.created',
                   'Cms\Models\Application.updated',
                   'Cms\Models\Application.nom',
                   'Cms\Models\Application.logo',
                   'Cms\Models\Application.zip',
                   'Cms\Models\Application.url',
                   'licence.*',
                   'paiement.*'
               )
           )
           ->execute();

If, i have no licence or paiement register, this request return nothing, if i remove the join i receive the application correctly

ty.



85.5k
edited Nov '16

i think in this case your joins are INNER, you might wanna try with left join


->join("Cms\Models\Licence", 'Cms\Models\Application.id = licence.application_id','licence', "LEFT")
         ->join("Cms\Models\Paiement", 'paiement.id = licence.paiement_id','paiement', "LEFT")

https://docs.phalcon.io/en/3.0.0/api/Phalcon_Mvc_Model_Query_Builder.html

Better just leftJoin method



1.8k

Ok thank you, it seems to work but, there is way to don't display 'paiement' table if its empty??