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: Models, useSoftDeletes not found in findAll #2658

Closed
Daniel-Monroy opened this issue Mar 2, 2020 · 16 comments
Closed

Bug: Models, useSoftDeletes not found in findAll #2658

Daniel-Monroy opened this issue Mar 2, 2020 · 16 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@Daniel-Monroy
Copy link

Bug
When obtaining records using findAll () and using useSoftDeletes in true, the method returns all records when it can return while $ this-> deletedField is null

CodeIgniter 4 version
4.0.2

Affected module(s)
Codeigniter\Model

@Daniel-Monroy Daniel-Monroy added the bug Verified issues on the current code behavior or pull requests that will fix them label Mar 2, 2020
@musmanikram
Copy link
Contributor

@danielMonroy96 Can you post some code. Because i checked tests and they worked as expected.
If you can post some code, will help to fix this

@Daniel-Monroy
Copy link
Author

Captura de pantalla de 2020-03-03 15-54-35
Captura de pantalla de 2020-03-03 15-55-43

Captura de pantalla de 2020-03-03 15-57-54

This is my code.

@Daniel-Monroy
Copy link
Author

Thanks for your help, in the first consultation it does not give me the expected results

@nyufeng
Copy link
Contributor

nyufeng commented Mar 4, 2020

deleted_at default value?

@Daniel-Monroy
Copy link
Author

Captura de pantalla de 2020-03-03 18-52-11

My model!

@nyufeng
Copy link
Contributor

nyufeng commented Mar 4, 2020

i want see you table structure. and row line.
ex:
image

image

@Daniel-Monroy
Copy link
Author

Captura de pantalla de 2020-03-03 19-02-31
Captura de pantalla de 2020-03-03 19-03-51

thanks

@nyufeng
Copy link
Contributor

nyufeng commented Mar 4, 2020

everything is normal.
image

image

@Daniel-Monroy
Copy link
Author

I'll try updating CI, because the problem persists

@arif-rh
Copy link
Contributor

arif-rh commented Mar 6, 2020

@danielMonroy96 If I see your code, It seems the issue is not from the Model but in your logic code

logic flow

I have tried to reproduce the issue but everything seem right. So can you confirm again, is your logic code is right?

@Daniel-Monroy
Copy link
Author

Daniel-Monroy commented Mar 9, 2020 via email

@MGatner
Copy link
Member

MGatner commented Mar 9, 2020

@danielMonroy96 is this issue resolved? If so feel free to close it.

@leutamo
Copy link

leutamo commented May 31, 2020

Hi everyone, i have same problem. i read the answer from Instrye, and all works fine.
the problem its in the Database fields, this suppose that not work's with int values(deleted_at)?.
well, with datetime in database works pretty :)
Thanks all!! only here found the answer thanks Instrye!!! you rock'ss!!
best regards!

@michalsn
Copy link
Member

This seems like resolved.

@JJohanGH
Copy link

JJohanGH commented Oct 28, 2020

Para resolver este problema, yo lo hice de esta manera:
entre a vendor\codeigniter4\framework\system\Model.php o sea el modelo que estas extendiendo
corregí la function findAll al igual que find:

`
public function findAll(int $limit = 0, int $offset = 0)
{
$builder = $this->builder();

	if ($this->tempUseSoftDeletes === true)
	{
		#$builder->where($this->table . '.' . $this->deletedField, null); -- JJohan 20201028 
		$builder->where($this->table . '.' . $this->deletedField, null);
	}

	$row = $builder->limit($limit, $offset)
			->get();

	$row = $row->getResult($this->tempReturnType);

	$eventData = $this->trigger('afterFind', ['data' => $row, 'limit' => $limit, 'offset' => $offset]);

	$this->tempReturnType     = $this->returnType;
	$this->tempUseSoftDeletes = $this->useSoftDeletes;

	return $eventData['data'];
}

`

@tanviet12
Copy link

tanviet12 commented Nov 21, 2021

findAll() will not working when:

  • $useSoftDeletes = true

  • deleted_at column with data type is timestamp.

Run this query to change deleted_at from timestamp to datetime:

alter table `your_table` modify column `deleted_at` datetime DEFAULT NULL;

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

9 participants