CodeIgniter Forums
Do CodeIgniter 4 model instances already have Query Builder methods loaded? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Do CodeIgniter 4 model instances already have Query Builder methods loaded? (/showthread.php?tid=91042)



Do CodeIgniter 4 model instances already have Query Builder methods loaded? - tarcisiodev1 - 06-09-2024

When I instantiate a model in CodeIgniter 4, does it already have the Query Builder methods loaded, or is there a better way to access them?


RE: Do CodeIgniter 4 model instances already have Query Builder methods loaded? - Kimotu - 06-10-2024

You usually do not have to load them manually. No matter whether I use
Code:
$model = model('App\Model\MyModel::class);
$model->find($id);
$model->where('id>',100)->get()->getResult();

or a ResourcePresenter which includes the model
Code:
protected $modelName = "App\Model\MyModel";
...
$this->model->find($id);
$this->model->where('id>',100)->get()->getResult();
I could always directly use the query builder.


RE: Do CodeIgniter 4 model instances already have Query Builder methods loaded? - kenjis - 06-10-2024

See https://codeigniter.com/user_guide/models/model.html#mixing-methods-of-query-builder-and-model
and https://codeigniter.com/user_guide/models/model.html#getting-query-builder-for-the-model-s-table