Welcome Guest, Not a member yet? Register   Sign In
Should i put only one table for model?
#1

[eluser]carlosgoce[/eluser]
Sorry for my bad English.

I find both cases, some people put in the same model different tables and classes, others just make 1 model foreach table. I just don't know what's the best choice.

What about relantionships between 2 models? Do i need to make another model to relate 2 models?

By the way... if i use private vars for my models... it's possible to do something like
$trackingsDb->insert('table', $model); i mean, the vars are private so the insert can't take the values of the vars...

Thank you for your time!
#2

[eluser]TheFuzzy0ne[/eluser]
From what I understand, quite a few people take the "1 table per model" approach, which sounds great, but I've no idea how they would handle joins.

I can't help thinking that ORM might be more suitable for your situation.
#3

[eluser]boltsabre[/eluser]
I think a lot of people use 1 table per model because the documentation/examples are often set out like this.\

When they designed CI (or any other MVC framework for that matter) they had absolutely NO idea what business application/logic you would use it for and they tend to promote to use 1 model for one table. That's good for some projects, but not for others. See below.

I tend to group models by "use cases". For example I have a model which handles blacklisting of forum posts, users by id/email, and ip addresses. In there I have interaction with my forum tables, user table/s, and blacklist table.

I could have made it more modular and divided it into three models, but why? I know in my case (it's a personal website) that this approach will be fine for now and in the medium term. In the long term, perhaps I will need to change it, but if you try to future proof everything you just end up making more work for yourself. Making code that "may" handle something in the future is a pretty big code smell to me.

So, as far as I am concerned it all comes down to an application by application approach. What works for me may not work for you. What you have to do is have a good idea of what model functions you need, and where they will be called. Once you have a good general overview of the application it should become pretty obvious what will work best for you.

Good luck with it.
#4

[eluser]carlosgoce[/eluser]
Thank you, i really appreciate your comment. So it seems i wasn't doing it wrong.




Theme © iAndrew 2016 - Forum software by © MyBB