craphunter
craphunter

Reputation: 981

Doctrine Query Result

I do have the following Doctrine query. My database is a MySQL.

    public static function getLastList($user_id){

    $user_id = 123;

    $q = Doctrine_Query::create()
            ->from('list l')
            ->innerJoin('l.listUser lu ')
            ->where('lu.user_id = ?', $user_id)
            ->orderBy('e.created ASC')
            ->limit(1)
            ->execute();

    if ($q == NULL) {
        print_r('false');
    } else {
        print_r('not false');
    }
}

I don't have a entry in my database with the user_id = 123. So what I expect is a "false". But "not false" is the result.

1.) Why?

2.) How can I divide with this specific query beteween "Yes, there ist a user" or "No, there is no user"?

Thanks!

Gunnar

Upvotes: 0

Views: 168

Answers (1)

Ruben
Ruben

Reputation: 2558

execute() returns Doctrine_Collection

You can check collection's size by calling count()

if ($q->count() == 0) {
    print_r('false');
} else {
    print_r('not false');
}

Upvotes: 1

Related Questions