Accesning a model in a model (bad practice?) |
[eluser]ennis[/eluser]
Hey guys I am pretty new to mvc and codeignitor. I do understand the concepts of mvc etc. I am wokring on a project with another programmer and he is accesing models from inside a model is this bad practice? should what is trying to do be achived through joins in sql or maybe binding data together from 2 different models in the controller? Any tips or ressource links would be mutch appreciated Bellow code example where in the client_relation_model the code accesses 2 other models to get some data this just seems very messy too me? Code: function findCompanyReferences($company_id){
[eluser]rogierb[/eluser]
yuck... :-) I'm a firm believer of join(t)s. Go for joins, much faster, less loading, compiling etc...
[eluser]Jeffrey Lasut[/eluser]
Take a look @ DMZ datamapper: http://ellislab.com/forums/viewthread/112904/ Will make your life a lot easier.
[eluser]John_Betong[/eluser]
Maybe I am a bad programmer but I would do it this way Controller code Code: //=================================================
[eluser]ennis[/eluser]
Yeah thanks for all the replys, just went through some more code that ihavent done and well will be suing some joins and then calling some models in the controller.. Right now the code calls the clients model model that calls the cliens_relation model that then call the client model to get tclietns pair them with tickets from the ticket model then calls the tick model to get the indivudal ticks for the ticket all this is run ever time I call getClients hehe so yeah not good So will refacture and break it up so that tickets are only pulled out when needed. |
Welcome Guest, Not a member yet? Register Sign In |