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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:10:13+00:00 2026-06-06T23:10:13+00:00

I apologize for the confusing title, I was a little stumped as to how

  • 0

I apologize for the confusing title, I was a little stumped as to how to word my question.

I am new to CakePHP, but am following along through the cookbook/tutorials nicely, however I have come up against something which I cannot find an answer to.

My structure is as follows:

'Invoices' hasMany 'InvoiceHistory'
'InvoiceHistory' belongsTo 'InvoiceHistoryDeliveryStatus'

Whereby, an invoice can have multiple invoice histories, and each history contains a delivery status id, which links to a name.

On the Invoice view (index.ctp) I am displaying a list of all invoices but wish to display the Most Recent Delivery Status Name (InvoiceHistory contains a date field so it can be sorted) – thereby displaying the ‘current Delivery Status’.
When I do:

$this->set('invoices', $this->Invoice->find('all'));

It does not go deep enough in what it returns to provide me with Delivery Status Names, nor have I deduced a way of only returning the most recent Invoice History within my result. I know how to do this manually with a MYSQL query but I figured that is probably just plain wrong.

What is the correct way of going about this while following CakePHP conventions?

  • 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-06T23:10:20+00:00Added an answer on June 6, 2026 at 11:10 pm

    Use Containable

    $this->Invoice->Behaviors->attach('Containable');
    
    $this->set('invoices', $this->Invoice->find('all', array(
        'contain' => array(
            'InvoiceHistory' => array(
                'InvoiceHistoryDeliveryStatus'
            )
        )
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize for the probably confusing title, but I wasn't quite sure how to
firstly, I apologize if my question sounds little confusing, I will try my best
I apologize in advance for the confusing question wording, but I couldn't figure out
I apologize for the newb question but have not found a solution online. I
I apologize for the somewhat confusing question, I'm not sure how to explain it
I apologize for the confusing post Title. This is what I mean: Lets say
I apologize if this is a noob question, but I can't seem to figure
My apologies if the title of this thread is a little confusing. What I'm
I apologize for any confusion from the question title. It's kind of a complex
I realize that the title may be somewhat confusing, so I apologize. Basically, this

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.