Welcome Guest, Not a member yet? Register   Sign In
Need enlightenment between libraries and models
#1

[eluser]Rey Philip Regis[/eluser]
Hi guys,

I need some enlightenment between models and libraries in CI. Here's a scenario that im having problem with. I have a query that has lots of joins, what do I do put it in a model or put it in a method in a library? Cause based from what I know Models are used for a specific table only. Any suggestions guys?

Hoping to have a response. Thanks in advance and good day.
#2

[eluser]xwero[/eluser]
Models don't need to be table specific. It's a good guideline to make models as less depended on a certain database structure as possible but there are queries that require you to use several tables because the performance is better that way. You can put this query in the model where it has the most affinity with.

Personally i add the tables that are used in the model to the comment section above the class Model_name extends Model line.
#3

[eluser]jdfwarrior[/eluser]
Agreed. I've never even heard of someone restricting a Model to a single table.

"Models are PHP classes that are designed to work with information in your database."

They are just there to provide you with a place to store code for database work as opposed to having everything in the Controller. I've never split mine up into a Model for an individual table. I split for functionality. Like, having a User_model to handle all user related actions such as, login authentication, registration, editing user settings, etc
#4

[eluser]Rey Philip Regis[/eluser]
thnks for the response..




Theme © iAndrew 2016 - Forum software by © MyBB