Join in model

hi I need select with join in model, example:

SELECT
    u.id, u.name, p.project_name
FROM
    user AS u
    JOIN project AS p ON p.user_id = u.id

how do it without phql?



36.5k
edited Mar '15

Hey man

You can use example below :

/**
 * Returns users which doesn't belong to any organization.
 *
 * @return mixed
 */
public static function getUnassigned()
{
    $query = User::query()
        ->columns(__NAMESPACE__ . '\User.*')
        ->leftJoin(__NAMESPACE__ . '\OrganizationUser', __NAMESPACE__ . '\User.id = ou.idUser', 'ou')
        ->where('ou.idUser IS NULL')
        ->execute();

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

    return false;
}

Also you can refer to here http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Model%5Criteria.html