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

  • Home
  • SEARCH
  • 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 432795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:06:37+00:00 2026-05-12T20:06:37+00:00

Assuming two database tables: Funds and Prices , in which Funds hasMany Prices .

  • 0

Assuming two database tables: Funds and Prices, in which Funds hasMany Prices.

What I wanted to do is to retrieve the latest 15 prices of a particular fund in a certain scenario. Is there a means in CakePHP to make a $this->Fund->find('all') call that would allow me to limit the number of rows to be retrieved from the associated Price table?

Note that I prefer not setting the 'limit' option in the Fund model’s $hasMany variable.

Note on accepted answer [Nov 2]:

In Jason’s answer which I had accepted, I personally opt for the bindModel solution as I felt despite feeling a bit “hack-y”, it bodes much better with me as to make a one-off override on the default Model bindings.

The code I used is as follows:

$this->Fund->bindModel(array(
    'hasMany' => array(
        'Price' => array(
            'limit' => 15,
            'order' => 'Price.date DESC'
        )
    )
);

No unbindModel is necessary. More information could be read from “3.7.6.6 Creating and Destroying Associations on the Fly” in the CakePHP manual.

  • 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-12T20:06:37+00:00Added an answer on May 12, 2026 at 8:06 pm

    As I understand the question, you don’t want to set the limit statically in the model. If you wish to use a hasMany association, there really isn’t any other way that I’m aware of other than changing that limit one way or another.

    Here are a few ways to dynamically change it:

    1. You could change the limit with a call to Funds->bindModel(). (This may require an unbindModel() first, but I can’t remember for certain)
    2. You could add a function to Funds to change the limit directly. (See example below.)
    3. If you’re feeling ambitious, you could write a Behavior to add the functionality to specify it per find() call similarly to the Containable behavior.

    Example for #2

    <?php
    function setPriceLimit($limit = 10) {
         // Assuming the association is 'Price'
         $this->hasMany['Price']['limit'] = $limit;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 286k
  • Answers 286k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer // comments are not allowed in old (pre 99) C… May 13, 2026 at 4:51 pm
  • Editorial Team
    Editorial Team added an answer Use $(this).data() At first I was going to suggest using… May 13, 2026 at 4:51 pm
  • Editorial Team
    Editorial Team added an answer use writeByte. socket.writeUTFBytes('Hello World'); socket.writeByte(0); socket.flush(); May 13, 2026 at 4:51 pm

Related Questions

Consider a database with tables Products and Employees. There is a new requirement to
When programming in PHP I always try to create meaningful 'models' (classes) that correspond
In several web application projects I've been a part of, the client asks to
Let's say I have two tables: Report Comment And assuming I have a database

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.