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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:57:14+00:00 2026-05-25T19:57:14+00:00

I am using cakephp containable to retrieve related models $this->Order->find(‘first’, array( ‘conditions’=>$conditions, ‘contain’ =>

  • 0

I am using cakephp containable to retrieve related models

$this->Order->find('first',
      array(
          'conditions'=>$conditions,
          'contain' => 
              array(
                 'OrderItem'=>array(
                     'Item'=>
                         array(
                            'order' => array('Item.item_number ASC')
                          )
                   ), 
             'Location','Campaign', "Customer")     
            )
       );

I’m using this to generate an invoice, and would like to have the items sorted by item_number.

But for some reason the sort isn’t working.

Any ideas?

The SQL generated is very long. but you can see the issue from this snippet that the order by is in the wrong query – – ie in the Item which is being select by id — only one item. (And there is a seperate query for each item in the order. )

  SELECT `OrderItem`.`order_id`, `OrderItem`.`item_id`,
 `OrderItem`.`quantity`,  `OrderItem`.`id` FROM `order_items` AS `OrderItem` WHERE
 `OrderItem`.`order_id` = (3144)

And

  SELECT `Item`.`id`, `Item`.`campaign_id`, `Item`.`item_number`, `Item`.`description`,
  `Item`.`order_unit`, `Item`.`order_price`, `Item`.`maxQuantity`, `Item`.`sale_unit`,
  `Item`.`sale_price`, `Item`.`approx`, `Item`.`min_weight`, `Item`.`max_weight`,
  `Item`.`avail`, `Item`.`filename` FROM `items` AS `Item` WHERE `Item`.`id` = 122 
 ORDER    BY `Item`.`item_number` ASC

What I would like to see is the first query do a inner join Items.id on OrderItem.item_id and order that query by item_number, but I see that containable generates separate queries for each related model.

  • 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-25T19:57:15+00:00Added an answer on May 25, 2026 at 7:57 pm

    You might want to try Linkable instead:

    https://github.com/Terr/linkable

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

Sidebar

Related Questions

I have a query using the Containable behavior in cakephp that looks like this
Using CakePHP, I created select-option form element with: echo $form->select('items', $numeration , array('selected' =>
I am using cakephp v1.26. I got a function in a controller like this:
I am using cakephp 1.2 and I have an array that appears to have
I'm using CakePHP for the first time and inside my controller I need to
I am using CakePHP 1.3. I have a few questions regarding CakePHP Models: 1)
I am having some issues with CakePHP's find() method and conditions in 'deeper' model
Greetings, I am trying to tear down query returned from find call using containable
I'm using cakePHP and I want to add a First and Last name column
using cakephp 2.0 rc3. following validation in my model: var $validate = array( 'loginname'

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.