Michael I find the model structure very flexible. I generally set recursive to -1 (this means my starting point is this record and none of its associations), and use the Containable behaviour; both of these are set in my custom app_model.php file, which means they apply to all models by default.
Before even touching a model I thrash out my actual data model as best as I can and then build my models around it starting with the associations and validation first. I like to make my data tightly integrated so that I can rely on relationships, but there are always occasions when a bit of data just doesn't link with another, but I know I am going to have to tie them together. I also build some generic find queries that I know I will use many times - these tend to be fully featured containing all the key related data for a given 'id'. Saves me building the same query over and over again and it's easier to maintain. When something doesn't fit I and I need to tie unrelated data together (which is rare) I do one of three things: - Store the unrelated data in the session, if it's small and appropriate, or even in a config file. - Use loadModel to make it available to 'this' controller, perform a find and store the result in an array for later manipulation = perhaps in the model. - Use the 'joins' elements to construct my own query (I prefer this to using 'query'). I also fall back on this method if I want to restrict a record set by a condition on one of its relationships using inner joins (Contain uses outer joins). When models are associated correctly you can indeed daisy chain across them to call an action on a distant model. Not sure that totally answers your question, but I hope it gets the ball rolling. Jeremy Burns Class Outfit [email protected] http://www.classoutfit.com On 4 Feb 2011, at 05:02, andy_the ultimate baker wrote: > will u please make it short and approachable to ur point, > becouse no one is having to read a long theses of ur query on the > work > so please make it shor and come in pints, so it would be fine to give > u answer > > regards > andy > > On Feb 3, 7:12 pm, Michael Carriere <[email protected]> wrote: >> Hello everyone! >> >> When recently approached to do some web development for a game whose code >> base was in dire need of a rewrite, I was determined on finding a stable, >> community supported framework to help speed up the process. I appreciate >> Cake's file organization, the way layouts are controlled, among other >> things, but I seem to be having a difficult time in the way I should be >> understanding the "M" in MVC. I've done enough web development in the past >> to be familiar with PHP, but more recently I've worked in object-oriented, >> compiled languages, as well as a few web tools built with Django. I could >> just give up and "do whatever works", but I feel like there's something >> powerful to be taken advantage of here, and I hope you guys can help! >> >> How "magical" is the find() function? Should I be able to run one exhaustive >> query and get back all the nested data that I need for a View to spit out? I >> guess a better question would be: do you find yourself calling find() on >> different sets of data, packaging them together yourself (presumably with >> the Set class, right?) and then passing that to the view to be displayed? >> >> I have some data that is loosely related, and while I can manage to get at >> all of it in one query, it requires me using Containable, and dropping 5-6 >> associations in. That just seems quite inefficient for me. (Maybe it's not?) >> >> Coming from many OO languages, after you define a class, you instantiate it >> as you want to work with an individual object, play with it as you want, and >> throw it out. Correct me if I'm wrong, but it seems that MVC's approach is >> more geared towards operating on all the data at once? Or at least in the >> case of working with a "Model". >> >> This leads to some confusion for me, because the majority of the instances >> where I need to access data, it's of a small subset of the data I'm storing >> in the DB for my model. My webgame has "Buildings" in it, which belong to a >> User's "Village". Sometimes I want to grab information from a specific >> Building, and other times I want to grab only the specific Buildings of a >> Village. Is it proper to be define a function within the model that grabs or >> manipulates data based on this, like >> $this->Village->getBuildingsByVillageId()? Better yet, how do you operate on >> 'instances' of your data as defined by your model? >> >> I may have some more questions later, but I'll start this thread with these >> two (albeit loaded) questions. >> >> Any help is appreciated, thank you! >> >> - Michael > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > [email protected] For more options, visit this group at > http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
