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.



64.0k
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.phalconphp.com/en/3.0.0/api/Phalcon_Mvc_Model_Query_Builder.html

Better just leftJoin method



395

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