Thursday 15 September 2011

mysql - Complex CakePHP query refactoring -


I just got a project and I need to work some code again so that an infinite scroller is still endorsed work properly.

Now the code is catching all the categories and their products, and the listing. I need to edit it so that only those categories which have active inventory have returned the products.

Here's the code that's finally worked:

  $ catData = $ it- & gt; Find ('All', array ('positions' => gt; array ('index type' = & gt; 'category', 'listing.living_id not'), 'joins' => array (array ( 'Table' = & gt; 'Pekka_product_graze_link', 'Alias' = & gt; Link ',' Type '= & gt;' LEFT ',' Conditions '= & gt; array (' link category_id = Category.category_id '), Array (' Table '= & gt;' Paca_products', 'Alias' = & gt;' product ',' type '= & gt;' LEFT ',' conditions' => .product_id = link.product_id '')), array ('table' = & gt; 'pkaka list', 'n Name '= & gt;' listing ',' type '= & gt;' LEFT ',' conditions '= & gt; array (' listing.product_ID = product, 'order' = '= & gt; $ date,' Listing .listing_start_date & lt; = '= Date, "Listing. & Gt; Category Category_name ASC', 'Border' = & gt; $ set_li MIT, 'Field' => Array ('Category .category_id category, category_name, indexer.url '),' group '= & gt; class' category_id', 'recurring' => gt;);   

Edit: Thanks for Dave, it's working now and I post it for future reference Received want. Maybe it helps someone else

"... only categories with products, who have active listings." < / P>

"... one way to combine these three questions in one, so that the first class-> search () function can get all the valid data."

To regain the data and to restrict it based on the areas of related models, you would want to use it.

It is difficult to answer your question without writing the code for you, then - try one, then come back and ask a more specific question if you have a problem with it.

No comments:

Post a Comment