Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count_all() bug #127

Open
djfd opened this issue Apr 19, 2016 · 0 comments
Open

count_all() bug #127

djfd opened this issue Apr 19, 2016 · 0 comments

Comments

@djfd
Copy link

djfd commented Apr 19, 2016

Hi,

original code of ORM::count_all() looks as:

public function count_all()
{
// remembering select columns
...
    $this->_build(Database::SELECT);
...
    // Add back in selected columns
    $this->_db_pending += $selects;

    $this->reset();

    // Return the total number of records in a table
    return (int) $records;
}

$this->reset(); looks wrong:

we are counting not all records in the table, but those matching the conditions set earlier,
eg. if we have 100 records in total, but only 55 of them do have ref_id = 55 then following code will return 55

$mdl = ORM::factory('Model')->where('ref_id', '=', 55);
echo $mdl->count_all();

so why do we reset builder entirely? Should not we do $this->reset(FALSE); instead?

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant