Welcome Guest, Not a member yet? Register   Sign In
Developing models quickly? Any tips...
#1

[eluser]Daniel H[/eluser]
My new projects data model design comprises 66 db tables. Developing models for each table is terrifying me! The thing is every model is practically the same - class variables the same as the field names, and reset(), save(), delete() methods.

Does anyone have a neat method for auto-generating their models or should I just get on with it and stop complaining?!
#2

[eluser]Sam Dark[/eluser]
Try Doctrine. http://www.doctrine-project.org/
#3

[eluser]Bramme[/eluser]
You could write a general model for all the identical tables that, in addition to the queries or whatever, receives a table name. Thus you won't need 66 models.
#4

[eluser]Daniel H[/eluser]
I like the idea of Doctrine but it'll probably take me a while to get my head around it. I guess I should just create a generic model for 'relationship' tables which by and large only have two fields.

Thanks.
#5

[eluser]Stefano G[/eluser]
Daniel, in a recent blog entry, Michael Wales posted an article about an Extended Model that has the all the basic methods you need (select all, get by id and so on):

http://michaelwales.com/asides/phpfours-...ter-model/

Of course this is just a start but you don't need to reinvent the wheel and you can use it either as a super model or as a base for implementing your own functionalities.

Anyway in my project I use a model for operating on different tables (passing the tabname as an argument) if the operations are the same (and the structures as well).

For example, if I need some tables for combobox I will name the id field 'id' and the desc 'desc' so I can use only one method/query for generating combobox from different tables.


cheers!



Stefano
#6

[eluser]Daniel H[/eluser]
Thanks for that link. I went about rolling my own for key tables by extending the model class to give a get(), save(), delete() and count() function for any model that extends it.

Here it is attached... MY_Model, then a model template, and then a DB helper. Let me know if you have any suggestions for making it better...
#7

[eluser]Stefano G[/eluser]
to me it looks ok, I think that the better approach is to have a Super-Model and then extending and implementing just small pieces... keep us informed!

Cheers!

Stefano




Theme © iAndrew 2016 - Forum software by © MyBB