//这是没用饥渴加载
$posts = Post::find('all', array('limit' => 10));
foreach ($posts as $post)
echo $post->author->first_name;
// 这是用了饥渴加载
// SELECT * FROM `posts` LIMIT 10
// SELECT * FROM `authors` WHERE `post_id` IN (1,2,3,4,5,6,7,8,9,10)
$posts = Post::find('all', array('limit' => 10, 'include' => array('author')));
// $posts = Post::find('all', array('limit' => 10, 'include' => array('author', 'comments')));
// $posts = Post::find('first', array('include' => array('category', 'comments' => array('author'))));
foreach ($posts as $post)
echo $post->author->first_name;这两个区别是?如何理解?
1 回答
- 1 回答
- 0 关注
- 1302 浏览
添加回答
举报
0/150
提交
取消