CodeIgniter Forums

Full Version: Models with parent::query not objects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Is this by design?  Why do parent::query calls not return model objects?  Am I confused here?  Huh
Yes, this is by design, for method chaining. $qb -> select(...) -> where(...) etc
So using method chaining, or "query builder" rather than just plain queries will result in getting my current model object?
I guess not. I just tried it and it is also just a generic StdClass. Does code igniter not have real object model mapping with a database?
See https://codeigniter4.github.io/userguide...ry-builder and the section below it

Using the model's query builder methods (which have been injected) will return your model instance.
Getting the query builder separately ($builder = $usermodel->builder(sometable)) gives you a separate query builder, and
its methods should return instances of itself.
The Entity class could be what you are loking for.
What do you understand by "real object model mapping with a database"?
Lonnie Ezell has a blog entry that might help ... https://www.patreon.com/posts/handling-model-25506357
Thanks, I am just coming to an older version of Code Igniter 3 and I understand most of the system, but I guess I just assumed CI_Model would auto map values to the model, but it seems like the people that developed this project treated models as a place to put function calls to a parent::query with huge SQL statements. Doesn't really seem like a real model that is mapped to an object and has a relationship with its associated data in the db.

I see CodeIgniter 4 is much more like what I enjoy using now. It seems I might have to use a different model class with Code Igniter and convert all the models in this code base or convert from CI3 to CI4 which is hard? I read in the documentation it is recommended to just start fresh and slowly port everything over?

Thanks
This might be old?

https://codeigniter4.github.io/CodeIgnit...ities.html

It says it supports entities. No?
CI4 has four levels of abstraction that you can use to work with relational databases: 1) drivers (SQL), 2) query builder, 3) models, 4) models & entities. Developers can choose what works best for them, or even build models that don't extend CodeIgniter\Model. It doesn't have support for document databases (yet).
Pages: 1 2