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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:39:28+00:00 2026-06-17T08:39:28+00:00

using cakephp 2. I have a model called pupils which $hasMany = array(‘PupilAction’, ‘TransientAction’,

  • 0

using cakephp 2.

I have a model called pupils which

$hasMany = array('PupilAction', 'TransientAction', 'TriageEvent')

and

$belongsTo = array('FormClass')

in my PupilsController I have the baked

$this->set('pupil', $this->Pupil->read(null, $id));  

I’d like to order the resulting related data, specifically the $hasMany = array(‘PupilAction’, ‘TransientAction’, ‘TriageEvent’) elements, by the field in each of those tables named date. I also want to include the full amount of info, I don’ want to restrict any fields from being returned, just to have those three tables ordered by date.

I can’t find a good example of how to use read() – most people seem to use find but I’d like to figure out this read one.

Can anyone kindly enlighten me?

  • 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-06-17T08:39:29+00:00Added an answer on June 17, 2026 at 8:39 am

    If you always need that data ordered by date, then in each model’s PHP file add the $order variable.

    public $order = ‘date’;

    or

    public $order = ‘PupilAction.date ASC’;

    This will ensure that those models return ordered results for associations, pagination and finds by default.

    Otherwise, you can use the order key for the containable behavior. Ensure you add the Containable behavior to the $actAs for each model (or in your AppModel.php)

    $record = $this->Pupil->find('first',array(
       'conditions'=>array('Pupil.id'=>$id),
       'contain'=>array('PupilAction'=>array('order'=>'PupilAction.date'))
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using CakePHP 2.0 I have a Model for my Users which is very
I'm developing a site using the CakePHP framework. I have a form which shows
I have a nested array that is compiled via the model in a CakePHP
I have created a temporary table using cakephp $this->Model->query() and inserted some records using
Hi all I am using Cakephp 2.x. I have an Events model(table) and a
I'm using Associations to Link Models together in CakePHP. I have a Player model
I'm using cakephp, I have a model comment with two fields : model_type and
I am building a portfolio website using CakePHP and have named my model 'Portfolio'
Using CakePHP 1.3 I have a fairly large model in CakePHP, and I'd like
I am using CakePHP 2.2.3. I have a contact form with a model without

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.