Skip to content

Instantly share code, notes, and snippets.

@AD7six

AD7six/find.php Secret

Created July 13, 2013 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AD7six/e84aa17eaa02f77ab79f to your computer and use it in GitHub Desktop.
Save AD7six/e84aa17eaa02f77ab79f to your computer and use it in GitHub Desktop.
<?php
$posts = $this->Post->find('all', array(
'contain' => array(
'Comment' => array(
'Commenter'
),
)
));
1 SELECT `Post`.`id`, `Post`.`user_id`, `Post`.`title`, `Post`.`body`, `Post`.`published`, `Post`.`allow_comments`, `Post`.`created` FROM `test_database_name`.`posts` AS `Post` WHERE 1 = 1 5 5 0
2 SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`user_id`, `Comment`.`comment`, `Comment`.`created` FROM `test_database_name`.`comments` AS `Comment` WHERE `Comment`.`post_id` IN (1, 2, 3, 4, 5) 3 3 1
3 SELECT `Commenter`.`id`, `Commenter`.`name`, `Commenter`.`bio`, `Commenter`.`created` FROM `test_database_name`.`users` AS `Commenter` WHERE `Commenter`.`id` = 1 1 1 0
4 SELECT `Commenter`.`id`, `Commenter`.`name`, `Commenter`.`bio`, `Commenter`.`created` FROM `test_database_name`.`users` AS `Commenter` WHERE `Commenter`.`id` = 2 1 1 0
5 SELECT `Commenter`.`id`, `Commenter`.`name`, `Commenter`.`bio`, `Commenter`.`created` FROM `test_database_name`.`users` AS `Commenter` WHERE `Commenter`.`id` = 1 1 1 0
@AD7six
Copy link
Author

AD7six commented Jul 13, 2013

5 posts, and 3 comments = 5 queries
100 posts and 3 comments = 5 queries
5 posts and 100 comments = 102 queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment