Welcome Guest, Not a member yet? Register   Sign In
Wrapping CI Models vs. Custom model
#1
Question 

First let me say that I'm enjoying CI4 as a framework. I have a question about best practices when it comes to Models as I'm still figuring everything out. 

In this scenario, an application has a database with ~12 tables. In some domains it makes sense to interact with the tables individually so extending CI's Model class is clearly the easiest route. However, other domains regularly require crossing table boundaries, at which point it's my understanding that you would lose a lot of the built-in benefits of CI's Model class. 

I could create a custom model, create the DB object and just go to town myself but that's a lot of work. I also think there will be scenarios where I will still need to interact with the tables individually, at which point I would still like to be using CI-extended Models. 

So here's my question: In this scenario, is it better practice to a) just create a custom model and do everything from scratch myself, or b) create the CI-extended Models for each table and then create a wrapper class that simply utilizes instances of the CI-extended Models?

My biggest quandary with b is any performance overhead that usage would incur, e.g. multiple database connections. 

Hopefully this makes sense. Thank you in advance.
Reply
#2

I would do something like your solution “B”:
Create a CI-extended models for all tables.
Then create a library that uses those models for when you need to interact with multiple tables.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB