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

left join

$data = Family::query()
    ->columns("*")
    ->leftJoin("FamilyUsers", 'a.family_id = Family.id', 'a')
    ->leftJoin("Users", 'b.id = a.user_id', 'b')
    ->where("a.family_id = $id_family")
    ->execute();

echo '<pre>';
print_r($data -> toArray());
exit;

But I can't get, I want to query data, could you tell me how do I change?


58.4k

Hey man

Do you have namespace in model ?

    query = User::query()
            ->columns(__NAMESPACE__ . '\User.*')
            ->leftJoin(__NAMESPACE__ . '\OrganizationUser', __NAMESPACE__ . '\User.id = ou.idUser', 'ou')
            ->leftJoin(__NAMESPACE__ . '\Organization', 'o.id = ou.idOrganization', 'o')
            ->where('ou.idUser IS NULL')
            ->execute();

        if ($query->count()) {
            return $query;
        }

        return false;