Assume this scenario: I need to retrieve 20 records, and call a method on each of them. So I do my Find, and get back an array. I then spin this, and do this:
$this->Widget->read(null, $id); What has just happened from a SQL perspective? 21 separate SQL executions? (One for the loop, and 20 to hydrate the resulting objects, one-by-one...) Deane On Jan 7, 4:12 pm, the_woodsman <[EMAIL PROTECTED]> wrote: > I had similar feelings to this when I first had to get some complex > data through CakePHP, thinking the results of a simple mysql_query or > an object would be much easier to work with than a 5 level deep array! > > >>Yet I still have nothing but these big arrays to deal with. > > That's the key point, and there are other ways to deal with it apart > from getting objects back from your results: > > -- Use generateList where you can > > generateList returns a simple array, and takes various params- it's > surprisingly powerful. > > -- Filter the results of your cake queries to make the arrays simpler > > The set class can help return simpler arrays (see the thinkingphp > blog for a good post on this), there's also a behaviour in the bakery > for simpler array results, and (perhaps in response to your previous > post) someone recently linked to a way to objectify the result arrays. > > -- run sql manually via model->query() in a method in your model, > like > ::getSimpleResultsForMyBigQuery(), and return the data just how you'd > like. > > -- use SQL views: often a SQL view is a nice way to take complex > queries out of your code. > > I hope with all those tools at your disposal, the use of results > arrays won't be a 'deal breaker' for you - It wasn't for me. > > On Jan 7, 8:42 pm, Robby Anderson <[EMAIL PROTECTED]> wrote: > > > Two ways jump out at me right off the bat. First, think of the default > > cake Model as a data access class only, and then define a business- > > logic class (that doesn't extend AppModel) to encapsulate your desired > > model functionality. > > > // Get results from data access model > > $results = $this->SomeModel->findWhatever(); > > > // Instantiate business logic class, assigning results to it, and then > > slice bread > > $myModel = new MyModelWithBusinessLogic($results); > > $myModel->sliceBread(); > > > Or just use afterFind() in a model, assigning the results to a model > > property, and build your business logic into the model that way. > > > function afterFind( $results ) { > > $this->_results = $results; > > > } > > > function sliceBread() { > > if ( empty($this->_results) { > > return false; > > } > > > // slice bread! > > > } > > > $this->SomeModel->findWhatever(); > > $this->SomeModel->sliceBread(); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---