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: Model()->find(null) should return null value #2350

Closed
SunilEver opened this issue Oct 19, 2019 · 1 comment
Closed

Bug: Model()->find(null) should return null value #2350

SunilEver opened this issue Oct 19, 2019 · 1 comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@SunilEver
Copy link

Describe the bug
When passing null in the find method of the Model it returns non null value. Default vaue of $id should not be null or if it is null it should not query the database and return null

/**
	 * Fetches the row of database from $this->table with a primary key
	 * matching $id.
	 *
	 * @param mixed|array|null $id One primary key or an array of primary keys
	 *
	 * @return array|object|null    The resulting row of data, or null.
	 */
	public function find($id = null)
	{
		$builder = $this->builder();

CodeIgniter 4 version
v4.0.0-rc.2.1

Affected module(s)
SYSTEMPATH/Model.php at line 354

Expected behavior, and steps to reproduce if appropriate
Should return null when $id is null

Context

  • OS: Ubuntu 16
  • Web server Apache/2.4.18
  • PHP version 7.3.9-1+ubuntu16.04.1+deb.sury.org+1
@jim-parry jim-parry changed the title Model()->find(null) should return null value Bug: Model()->find(null) should return null value Oct 19, 2019
@jim-parry jim-parry added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 19, 2019
@lonnieezell
Copy link
Member

In this case this is the desired behavior since this method can also be used as part of chaining together commands that could include where's, etc. In that case, it could actually return results.

There was a big long discussion about this and other methods a year or so back and it was done this way for consistency with other core methods.

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

No branches or pull requests

3 participants