secret
Created

  • Download Gist
find.php
PHP
1 2 3 4 5 6 7 8
<?php
$posts = $this->Post->find('all', array(
'contain' => array(
'Comment' => array(
'Commenter'
),
)
));
sql.log
1 2 3 4 5
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

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.