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

phql, where statement in joined table

hi all, how can i make where statement in phql query builder for field in joined table my phalcon configuration is using module and namespace

sample 2 tabel

  • tabel user -- field user_id -- fied user -- field role_id

  • tabel role -- field role_id -- field role

i want select from user join with role where role="operator"

tanks before



4.5k
Accepted
answer
edited Oct '14

i make it work

        $builder = $this->modelsManager->createBuilder();
        $builder->from(array('u'=>'Sistem\Model\CrUser'));
        $builder->join('Sistem\Model\CrPeran', 'p.peran_id = u.peran_id','p');
        $builder->where('p.peran = :slopok: or p.peran = :wader:',array('slopok'=>'Operator','wader'=>'Administrator'));
        $builder->andWhere('user_aktif = :x:', array('x' => 0));

        $user = $builder->getQuery()->execute();
        foreach ($user as $x) {
            echo $x->user." ".$x->CrPeran->peran."<br>";
        }

thanks