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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:38:55+00:00 2026-06-13T18:38:55+00:00

I have 3 Models. Each one has a column that holds a DateTime called

  • 0

I have 3 Models. Each one has a column that holds a DateTime called “created” After performing a find() on each model, I would like to combine the 3 lists and sort them according to this created date. Is there an easy way to do this in cakephp. Here is the code snippet where I use find() to query the database. I do this 3 times, once with each Model. Is there a way to combine and sort these as I have described?

$this->set('users',
    $this->Account->find('all', 
        array('conditions'=>
            array('OR'=>
                array('Account.organization_name LIKE'=>'%'.$words.'%', 
            'Account.first_name LIKE'=>'%'.$words.'%',
            'Account.last_name LIKE'=>'%'.$words.'%', 
            'Account.middle_name LIKE'=>'%'.$words.'%')))),
    $this->paginate()); 
  • 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-13T18:38:56+00:00Added an answer on June 13, 2026 at 6:38 pm

    I do that by combining all the different models into one array and doing Set::sort on that, like this:

    $allEntities = array();
    
    $articles = $this->Article->find( ... );
    foreach ($articles as $k => $v) {
        $allEntities[] = $v['Article'];
    }
    $documents = $this->Document->find( ... );
    foreach ($documents as $k => $v) {
        $allEntities[] = $v['Document'];
    }
    $videos = $this->Video->find( ... );
    foreach ($videos as $k => $v) {
        $allEntities[] = $v['Video'];
    }
    
    if (sizeof($allEntities) > 1) {
        $allEntities = Set::sort($allEntities, '/created', 'DESC');
    }
    

    If you need to have a model name for the entities, you can do that for example like this:

    $videos = $this->Video->find( ... );
    foreach ($videos as $k => $v) {
        $v['Video']['modelName'] = 'Video';
        $allEntities[] = $v['Video'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models: Show and Venue . Show has one venue while each
I have two models that are associated with each other. Customer has_one :primary_contact And
I have a number of models that store words as a string with each
I have a model in Rails called Recipe. The recipe model contains ingredients. Each
So I have a city model. Each city has a Name attribute as well
I have the model Called Plan Plan has state and city associated with it
Imagine that I have a model that describes the printers that an office has.
I have a data table. Each row of the table has a commandButton called
We have 3 entities that relate to each other as such: Foo has many
I have an entity model with User and Person entities, such that each User

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.