Welcome Guest, Not a member yet? Register   Sign In
Models with parent::query not objects
#1
Question 

Is this by design?  Why do parent::query calls not return model objects?  Am I confused here?  Huh
Reply
#2

Yes, this is by design, for method chaining. $qb -> select(...) -> where(...) etc
Reply
#3

So using method chaining, or "query builder" rather than just plain queries will result in getting my current model object?
Reply
#4

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?
Reply
#5

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.
Reply
#6

The Entity class could be what you are loking for.
What do you understand by "real object model mapping with a database"?
Reply
#7

Lonnie Ezell has a blog entry that might help ... https://www.patreon.com/posts/handling-model-25506357
Reply
#8

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
Reply
#9

This might be old?

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

It says it supports entities. No?
Reply
#10

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).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB