Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:13:51+00:00 2026-05-23T13:13:51+00:00

So I have a Cake query that looks something like this: $forthcomingReleases = $this->Release->find(‘all’,

  • 0

So I have a Cake query that looks something like this:

$forthcomingReleases = $this->Release->find('all', array(
        'contain'=>array('Artist.name', 'Artist.slug', 'Releasetype.type', 'Format.Mediatype.name'),
        'conditions'=>array('release_date >' => date('Ymd'), 'Release.is_deleted' => false),                
        'order'=>array('release_date DESC'),
        'limit'=>10
    ));

And what I’m seeing in the SQL dump is this sort of thing:

45  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 10021      1   1   167
46  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 10159      1   1   168
47  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 10021      1   1   170
48  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 10159      1   1   168
49  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 1338       1   1   169
50  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 10159      1   1   187
51  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 569        1   1   211
52  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 569        1   1   168
53  SELECT `Artist`.`name`, `Artist`.`slug` FROM `artists` AS `Artist` WHERE `Artist`.`id` = 10451      1   1   182
54  SELECT `Releasetype`.`type` FROM `releasetypes` AS `Releasetype` WHERE `Releasetype`.`id` = 901         1   1   170
55  SELECT `Releasetype`.`type` FROM `releasetypes` AS `Releasetype` WHERE `Releasetype`.`id` = 901         1   1   171
56  SELECT `Releasetype`.`type` FROM `releasetypes` AS `Releasetype` WHERE `Releasetype`.`id` = 901         1   1   180 
57  SELECT `Releasetype`.`type` FROM `releasetypes` AS `Releasetype` WHERE `Releasetype`.`id` = 900         1   1   171
58  SELECT `Releasetype`.`type` FROM `releasetypes` AS `Releasetype` WHERE `Releasetype`.`id` = 900         1   1   183
59  SELECT `Releasetype`.`type` FROM `releasetypes` AS `Releasetype` WHERE `Releasetype`.`id` = 901         1   1   171
60  SELECT `Releasetype`.`type` FROM `releasetypes` AS `Releasetype` WHERE `Releasetype`.`id` = 901 

(This is just an excerpt for illustration purposes, there are lots more queries.)

Even if each of these queries is only taking <200 ms, it still seems they might be adding up to something significant, and this is especially annoying when so many of the queries are duplicates – e.g. all the Releasetype.types being either 900 or 901.

Is there any way I can refactor my query, my model relationships, or something else so that the data is retrieved in considerably fewer calls?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:13:51+00:00Added an answer on May 23, 2026 at 1:13 pm

    Cake is doing one ‘main’ query. “Release” model find in this case, and for each row that is found there its doing a query to get the data you have specified in ‘contain’.

    This is expected behavior.

    A big problem I see is your statement ‘these queries is only taking <200 ms’. Imo they should not be taking more than 1ms or even 0ms. It would seem you need to index that table properly.

    I am not particularly fond of forcing cake to do joins, as if it was meant to be a join the cake devs would have made it join.

    If you really want to lower the query count even though its not needed, look at a) linkable behavior b) bindModel c) adhoc-joins

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this data spited out from my cake php query.. This is the
I have an SQL query like this. When iam executing it though my php
I have models that look like this (simplified of course): class Product(models.Model): product_code =
I have a form that has all the fields pulled dynamic from a database
I have a Goal model that HasAndBelongsToMany Users. This HABTM is named Participant. When
I have a query along the lines of this: SELECT * FROM posts WHERE
I have the following code: $this->Permissions->updateAll( array('Permissions.user' => $newuser), array('Permissions.user' => $originaluser) ); But
I have a CakePHP query that uses subqueries. While I've found documentation that shows
You can't have your cake and eat it too, apparently. I'm currently using the
I have go TCPDF setup in my cake php install and am now trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.