Welcome Guest, Not a member yet? Register   Sign In
best practice to write a User class that tale data from different db tables
#1

(This post was last modified: 02-17-2021, 06:43 AM by filit.)

Hi,

I am new to CI in general and to CI4. I am loving it but I have a LOT of doubts about what are the best practices to work with Controllers, Models, Entities etc...

Now I am facing this problem. It SEEMS (I could be wrong) that a Model should be related to a given table in database. Is it correct?

If so, what if a entity is populated with data from 2 different tables?

I explain...

For GDPR reasons I would like to split users data in 3 different tables.
Thus, the User class (I should create an Entity, I suppose) must load data from these 3 tables.

Is it correct to create 3 Models (one for each table), and then in the Controller...
1) I create the User object (again, I suppose I should an Entity, but I am not sure)
2) I use the 3 Models to get the data
3) I use some kind of customized "fill" function to set the data in the User object

I saw in the Codeignator Foundation on-progress book that there is the possibility to create a UserManager class as well. Shoud I go for this option? And, if so, where should I put the logic to get the data from the 3 tables (directly in the class, or use 3 different Models, or just 1 model...)?

As you can see I am a bit confused about it.
Are there any best practices about that?

Thank you very much for any advice
Reply




Theme © iAndrew 2016 - Forum software by © MyBB