How to call Model::maximum aggregator when there are no rows

It appears as though the Model::maximum aggregator method fails without an exception when there are rows in the database.

Is there any way to get around performing a count operation first?



6.3k
edited Dec '14

It doesn't fail. It returns null when no result matches your criteria. Example:

    $maximum = Account::maximum(
        array(
            'column'  => 'id'
        )
    );

    var_dump($maximum); // Will output "null" as there is no user in my database

    if (!is_null($maximum)) {
        // This is your best bet as Model::maximum() may return INT, STRING, FLOAT
        // if a result is found or NULL if no result is found
    }