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

[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?!

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

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.

[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.


[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):


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.



[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...

[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!



Theme © iAndrew 2016 - Forum software by © MyBB