Thanks for the reply.

I am using "recursive = 2" in the example because although it is not
needed in the sample code, I do need it in the real scenario where I
have other associations.

Yes, I am familiar with this article and tried the expects() method.
It can help when you need to remove unwanted associations but in case
when you do need the information from these associations and don't
want to have them removed, expects() doesn't help you to reduce the
redundant queries.

My point being, I don't understand why cake generates these queries in
the first place, all the information was already retrieved in the
initial query so I assumed this is a bug or otherwise unintentional
behavior.


On Apr 10, 6:13 am, "dericknwq" <[EMAIL PROTECTED]> wrote:
> This was my point when I 
> postedhttp://groups.google.com/group/cake-php/browse_thread/thread/b73a9a23...
>
> Anyways, I don't suppose you will need a level 2 recursive call based
> on the Model you've shown. Buthttp://bakery.cakephp.org/articles/view/185
> should help greatly. :)
>
> On Apr 10, 12:54 am, "barduck" <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I was looking at my SQL debug logs and seeing a lot of redundant
> > unnecessary queries which I don't think should be there at all. I am
> > using the nightly build of 1.2 from couple of days ago but I was
> > seeing this with 1.2 for quite a while.
>
> > So I created a very basic scenario and this is still reproducing, just
> > two DB tables and two cake models:
>
> > class Category extends AppModel
> > {
> >         var $name = 'Category';
>
> > }
>
> > class Product extends AppModel
> > {
> >         var $name = 'Product';
>
> >         var $belongsTo = array('Category');
>
> >         var $recursive = 2;
>
> > }
>
> > In my products controller, I want to get all products:
>
> > $products = $this->Product->findAll();
>
> > And this is what I see in the SQL log:
>
> > 1       DESC `products`         3       3       5
> > 2       DESC `categories`               2       2       5
> > 3       SELECT `Product`.`id`, `Product`.`name`, `Product`.`category_id`,
> > `Category`.`id`, `Category`.` name` FROM `products` AS `Product` LEFT
> > JOIN `categories` AS `Category` ON (`Product`.`category_id` =
> > `Category`.`id`) WHERE 1 = 1            12      12      1
> > 4       SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 1            1       1       1
> > 5       SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 1            1       1       0
> > 6       SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 1            1       1       0
> > 7       SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 1            1       1       0
> > 8       SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 3            1       1       0
> > 9       SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 3            1       1       1
> > 10      SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 3            1       1       0
> > 11      SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 3            1       1       3
> > 12      SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 3            1       1       1
> > 13      SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 3            1       1       1
> > 14      SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 2            1       1       1
> > 15      SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 2            1       1       0
>
> > What are all the SELECT queries from categories table doing there?
> > They are already included in the main query with the LEFT JOIN and why
> > is there a separate query for each product row even if the same
> > category was already fetched?
>
> > This is just a sample DB, in my real scenario with many more
> > associations, a findAll() query generates over 1000 redundant queries
> > which takes some time to execute.
>
> > Can anyone shed some light on this?
>
> > Thanks.


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to