![]() |
Problem with Model()->find() and Model()->findAll() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Problem with Model()->find() and Model()->findAll() (/showthread.php?tid=74539) Pages:
1
2
|
Problem with Model()->find() and Model()->findAll() - workoverflow - 10-06-2019 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. For example, i have model UserModel which based on BaseModel which extends Model. PHP Code: class UserModel extends BaseModel Table users has 1 row with id = 1 When i try to get row from DB with find() or findAll() i get Null result. I don't known why it's happening. PHP Code: $items = (new UserModel())->find(1); // will be null PHP Code: $items = (new UserModel())->where('id', 1)->get()->getRowArray(); // will be array with user data Tell me, please, what i doing wrong? I created issue on github.com, but jimm-parry redirect me to this forum. RE: Problem with Model()->find() and Model()->findAll() - ciadmin - 10-06-2019 Model already has $table and $primaryKey properties. Shouldn't your model have a constructor, where it sets those? Code: public function __construct() { You don't initialize the $DBGroup property, which might affect your outcome. RE: Problem with Model()->find() and Model()->findAll() - ciadmin - 10-06-2019 More thoughts: 1) I presume UserModel is namespaced, and that you have a something like "use App\Models\UserModel;" 2) The primary key is supposed to be a string, and you are passing an int. Should there be some casting? RE: Problem with Model()->find() and Model()->findAll() - dave friend - 10-06-2019 Tell us about BaseModel. Does it extend CodeIgniter\Model? What are your namespace statements? (10-06-2019, 01:01 PM)ciadmin Wrote: Model already has $table and $primaryKey properties. Shouldn't your model have a constructor, where it sets those? The docs show assignments to those and other Model properties in the class definition. Since the values are not typically used in a dynamic way there is no reason not to do it that way. RE: Problem with Model()->find() and Model()->findAll() - workoverflow - 10-06-2019 (10-06-2019, 01:22 PM)dave friend Wrote: Tell us about BaseModel. Does it extend CodeIgniter\Model? What are your namespace statements? I have app/Models/BaseModel which extends CodeIgniter\Model and contains some methods specific for my project. PHP Code: namespace App\Models; All my model extends BaseModel, and before update to last version I don't call __construct() in sub classes. For example, i put code of one class which building menu. I rewrited it with MenuModel()->get()->getResutArray(), because findAll() don't work after all. PHP Code: <?php RE: Problem with Model()->find() and Model()->findAll() - workoverflow - 10-06-2019 (10-06-2019, 01:04 PM)ciadmin Wrote: More thoughts: 1) All my models are in namespace app/Models/Main 2) I use protected $primaryKey = 'id'; it's not a int I known, you guess that i'm dummy, but i'm sure that something happened with Model. I have used it without any problems yesterday. RE: Problem with Model()->find() and Model()->findAll() - ciadmin - 10-06-2019 The last update to Model was on Sept 29th. Did you update your CI4 framework yesterday? How have you installed it? (manual, composer framework, composer appstarter) RE: Problem with Model()->find() and Model()->findAll() - workoverflow - 10-07-2019 (10-06-2019, 04:04 PM)ciadmin Wrote: The last update to Model was on Sept 29th. I use composer for update project dependencies. RE: Problem with Model()->find() and Model()->findAll() - MGatner - 10-08-2019 @workoverflow Composer will update against various sources depending on where you installed it from. Open composer.json and verify your CodeIgniter dependency looks something like this: "codeigniter4/codeigniter4": "dev-develop" RE: Problem with Model()->find() and Model()->findAll() - workoverflow - 10-09-2019 (10-08-2019, 06:17 AM)MGatner Wrote: @workoverflow Composer will update against various sources depending on where you installed it from. Open composer.json and verify your CodeIgniter dependency looks something like this: This is my current config of Composer. Code: "require": { |