Welcome Guest, Not a member yet? Register   Sign In
Best practices with models
#1

[eluser]ilSignorCarlo[/eluser]
Hi,
I started using CodeIgniter some months ago and I used it in about 3 projects.

Every time I started a new project I was not sure which model to create. In the last project I ended up using two models: one for getting data and another one for inserting.

I read that a lot of people create a model for every table in the database. I still am not sure if this is a good practice. I mean, when I create a query that get data from two or more tables, in which model shall I put it?

How do you usually manage your models in your projects?

Thanks,
Carlo
#2

[eluser]Myles Wakeham[/eluser]
You might want to do some Googling for Object Relationship Mapping (ORM) to get an understanding about how object classes (as in Models) are intended to work with database tables. From experience, for the most part you can map classes one to one with tables. But it really depends on your system design and if you have done solid data modeling of your database before, you should also do class diagramming to get a handle on how these classes will be used in your application. It should then become pretty straightforward to define the classes you will need, and then simply translate those into models for your CI apps.

I'm not sure I'm with you on the idea of creating two models - one for getting data and one for inserting. Isn't that just two different methods of one class? (ie. if you have a class for 'Customer' you'd have its properties clearly defined (ie. Name, Address, phone, etc.) and its methods (Add, Edit, Delete, etc.).

I guess you'd have to explain to us how your models are designed in order to understand your question further.

Myles
#3

[eluser]kgill[/eluser]
Search the forums this question has been done to death, you'll find numerous viewpoints to consider.




Theme © iAndrew 2016 - Forum software by © MyBB