# Cakephp 3 - limit () and contained model

**URL:** <https://discourse.cakephp.org/t/cakephp-3-limit-and-contained-model/804>\
**Category:** Need Help\
**Created:** [July 25, 2016, 9:14am UTC](https://discourse.cakephp.org/t/cakephp-3-limit-and-contained-model/804 "2016-07-25T09:14:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lupy](https://avatars.discourse-cdn.com/v4/letter/l/9e8a1a/32.png) [@lupy](https://discourse.cakephp.org/u/lupy)\
**Post date:** [July 25, 2016, 9:14am UTC](https://discourse.cakephp.org/t/cakephp-3-limit-and-contained-model/804/1 "2016-07-25T09:14:14Z")

</div>

I have two models, named Post and Comment, which are linked by Post hasMany Comment and Comment belongsTo Post.  
I want to fetch all posts with the first five comments each. I would use this code:

> $this-\>Posts-\>find(‘all’)  
> -\>contain([  
> ‘Comments’ =\> function($q) {  
> return $q  
> -\>order(‘created ASC’)  
> -\>limit(5);  
> }  
> ]);

This works incorrectly with the limit(5). Please help to solve this.

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [October 24, 2016, 1:50pm UTC](https://discourse.cakephp.org/t/cakephp-3-limit-and-contained-model/804/2 "2016-10-24T13:50:39Z")

</div>

I’m facing the same problem.  
Did you find something that could help ?

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [October 25, 2016, 3:25am UTC](https://discourse.cakephp.org/t/cakephp-3-limit-and-contained-model/804/3 "2016-10-25T03:25:46Z")

</div>

Please refer this [https://github.com/cakephp/cakephp/issues/8060](https://github.com/cakephp/cakephp/issues/8060)
