Welcome Guest, Not a member yet? Register   Sign In
MVC Design Question - Multiple Models or specific methods?
#1

[eluser]Majd Taby[/eluser]
Hey, Take a look at http://jtaby.com:82/dump/jtaby-frontend.jpg . You'll notice that the page (which corresponds to a controller), pulls data from multiple tables.

There are two ways to do this:

In my model, have methods such as:
loadLast10JournalEntires, loadLast5PluginsByDateAdded, and getLatestStableReleaseInfo

Or i could have the controller load multiple models

Off the top of my head, the first would _probably_ be more efficient, but the latter would be more reusable.

What would you do?
#2

[eluser]gtech[/eluser]
I am writing a large project in CI,

As a matter of preference I tend to group tables in my datamodel together (e.g users, user_lookups) and have a model for each group which would contain all the functions for manipulating the tables (e.g. add_user, delete_user).

sometimes I call multiple models in the controller, but the models are not grouped by controller functionality, more by the way the datamodel is structured.

Somtimes I load a model in a model, for example I have a loggingsdb, which logs all database activity and the user who did the actions, I load this model in the constructor of my other models. Sometimes I may want to make calls to another model without loading it in the constructor, if this is the case you need to make an instance of the CI object [url="http://ellislab.com/forums/viewthread/63953/"](see thread 63953)[/url].

hope that helps, I had to keep some kind of structure to my tables (I have about 25) as it makes my code easy to follow. other people have different approaches most probably
#3

[eluser]Majd Taby[/eluser]
The benefit I see in that is the fact that it's all more logically grouped. Let's say you change a field in a table, then you only need to modify one file. Which is more maintainable, but on the other hand adds the overhead of loading another model.

What do you guys think?
#4

[eluser]gtech[/eluser]
I see your point, personally if its a large project I think if its not maintainable your going to shoot yourself in the foot, especially if your going to pass it to someone else. A small project might not be such an issue, but then I am not sure overheads will be.

Lets just say CI seems to cope with the way I have structured the code perfectly well. maybe you could do some timings? I don't know if anyone has done any analysis on this (i would be interested to find out)?
#5

[eluser]Majd Taby[/eluser]
yeah, so would i, i'm just too lazy to do it myself (sorry)
#6

[eluser]Majd Taby[/eluser]
i would love some more input on this
#7

[eluser]wiredesignz[/eluser]
If a model relates to a single table then it's reuseable with its table in other applications.




Theme © iAndrew 2016 - Forum software by © MyBB