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 7432857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:31:28+00:00 2026-05-29T09:31:28+00:00

I have the following find function: $this->MyModel->find(‘all’, array(‘conditions’ => array(‘id’ => $id))); which returns

  • 0

I have the following find function:

$this->MyModel->find('all', array('conditions' => array('id' => $id)));

which returns an array of this form

Array
(
    [Model1] => Array
        (
            [Model1] => Array
                (
                    ...
                    ...
                )
        )
    [Model2] => Array
       (
            [0] => Array
                (
                    ...
                    ...
                )
            [1] => Array
                (
                    ...
                    ...
                )
            [2] => Array
                (
                    ...
                    ...
                )
            ...
            ...
            ...

            )
)

How do I alter the the find all to limit how many elements the second model are fetched (Model2)?

I can add conditions => array( 'limit' => 10 ) but that limits the number of elements of the outer array – not Model2 i.e. the second nested array!

Any ideas? Thank you :).

  • 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-29T09:31:28+00:00Added an answer on May 29, 2026 at 9:31 am

    You should use cake’s containable behaviour here to limiting the records of your second model. Here’s what you can do using containable to achieve this.

        $this->Model->contain = array('Model2' => array('limit' => 10));
        $this->Model->find('all', array('conditions' => $conditions));
    

    Now you will get maximum of 10 records from Model2.

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

Sidebar

Related Questions

I have the following jQuery code: $(.save_button).click(function() { var $form = $(this).closest(div.info_section).find(form); url =
I have the following jQuery code which all works fine: $(#sidebar .m3, #sidebar .m5).toggle(function()
I have the following code: $(document).ready(function(){ $(.datepicker).each(function() { $(this).datepicker({ beforeShowDay: function(date){ return [$(this).parent().find(span.days).html(), ]
I have the following jQuery: $(this).closest('div.mcoup').find('div.delcoup').slideToggle(400) .siblings().children('div.delcoup').slideUp(400); What I'm trying to do is get
I have the following code: $(document).ready(function() { $('.container').ready(function() { var v = new Video($(this));
I have created following function to fill field of a form page, there is
I have the following code: var parentEls = $(root) .find(credit standard) .parents() .map(function ()
I have the following code: var shadow = #FF00FF 0 50px 90px inset; $('#element').find('a.thumbnail').hover(function()
I have the following script: $("tr.member_profile_comment_row_frame").mouseover(function () { $(this.element."img.member_profile_comment_show_delete_button").show(); }); $("tr.member_profile_comment_row_frame").mouseout(function () { $(this.element."img.member_profile_comment_show_delete_button").hide();
I have the following jQuery function (simplified): function doSomething(el, str) { el.find('.class').text(str)); } Don't

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.