Welcome Guest, Not a member yet? Register   Sign In
Problem with Model()->find() and Model()->findAll()
#11

(10-06-2019, 12:03 PM)workoverflow Wrote: Hi! I have faced with problem with Model()->find() and Model()->findAll(). If i call ones of this methods i get null. It's doesn't work after update to 4.0.0-rc.2.1 with composer.

Hi guys, I have the same problem.
I'm using CI v4.0.0-rc.3 and couldn't get results using find() and findAll() methods.

Just two simple files.

Product model:
PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;

class 
Product extends Model
{
    protected 
$table 'products';
    protected 
$primaryKey 'ID';


Catalog controller:
PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
App\Models\Product;

class 
Catalog extends Controller
{
    public function 
product(string $ID '')
    {
        
$productModel = new Product();
        
// working
        
$product $productModel->where('ID'$ID)->get()->getRowArray();
        
d($product);

        
// not working
        
$product $this->productModel->find($ID);
        
d($product);
    }


Could you help me in fixing it?
Thanks for your support.
Reply
#12

Fixed it, sorry.
Reply
#13

<?php namespace App\Models;
use CodeIgniter\Model;
class TestModel extends Model
{
protected $table = 'prova';
protected $primaryKey = 'id';

protected $returnType = 'array';
protected $useSoftDeletes = false; //With false work??
Reply
#14

Indeed, also in my case, on using:
protected $useSoftDeletes = false;

it worked.
Reply
#15

(05-16-2020, 04:44 AM)Anwar Wrote: Indeed, also in my case, on using:
protected $useSoftDeletes = false;

it worked.

The same thing happened to me, I did not understand what happened, then look at the code and in the direction "system \ Model.php" change the line 369 "$ builder-> where ($ this-> table. '.'. $ this-> deletedField, null); " by $ builder-> where ('('. $ this-> table. '.'. $ this-> deletedField. "is null or". $ this-> table. '.'. $ this-> deletedField. ' = 0) ');


only return results if delete_at column is null by default and change to allow with null and 0
Reply




Theme © iAndrew 2016 - Forum software by © MyBB