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

Bug: calling countAllResults after find($id) produce wrong result #2705

Closed
arif-rh opened this issue Mar 15, 2020 · 1 comment
Closed

Bug: calling countAllResults after find($id) produce wrong result #2705

arif-rh opened this issue Mar 15, 2020 · 1 comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@arif-rh
Copy link
Contributor

arif-rh commented Mar 15, 2020

Describe the bug

calling countAllResults after find($id) produce wrong result. for example, I made below tests:

    public function testFindIdCountAllResults()
	{
		$model = new UserModel($this->db);

		$model->find(1);

		$this->assertEquals(1, $model->countAllResults());
	}

	public function testFindArrayCountAllResults()
	{
		$model = new UserModel($this->db);

		$model->find([1,2]);

		$this->assertEquals(2, $model->countAllResults());
	}

and both produce an error, because all countAllResults is 4

find countAllResults

This issue only happen when we passing $id to find method. If we omit it, it will work fine, because without passing $id it will call findAll instead.

CodeIgniter 4 version

4.0.2

Affected module(s)

CodeIgniter\Model

Expected behavior, and steps to reproduce if appropriate

Make test as description above to reproduce the issue

Context

  • OS: Windows 10
  • Web server Apache 2.4.37
  • PHP version 7.3.1
@arif-rh arif-rh added the bug Verified issues on the current code behavior or pull requests that will fix them label Mar 15, 2020
arif-rh added a commit to arif-rh/CodeIgniter4 that referenced this issue Mar 15, 2020
@lonnieezell
Copy link
Member

To the best of my knowledge that's not how the count_all_results() method in previous versions of CI3 ever worked, and it's not how the method is intended to work in CI4 either.

if you do $users = $model->find(1) it returns a Result instance. All you have to do is grab the results from that and count() the results. This method is intended to perform a COUNT query on the database itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants