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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:44:26+00:00 2026-06-08T10:44:26+00:00

I have a 3 level Models structure: Model_Race has_many Model_Class Model_Class has_many Model_Driver Now,

  • 0

I have a 3 level Models structure:

  • Model_Race has_many Model_Class

  • Model_Class has_many Model_Driver

Now, imagine Model_Class and Model_Driver have an order_index property to keep them in order.

Is there a clean way to get a Race and have the Class and Driver’s sorted correctly?

  • 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-08T10:44:28+00:00Added an answer on June 8, 2026 at 10:44 am

    The documentation clearly shows this, I somehow missed it:

    Find Array Syntax

    $race = Model_Race::find($id, array(
            'related' => array(
                'class' => array(
                    'order_by' => array('order_index' => 'asc'),
                    'related' => array(
                        'driver' => array(
                            'order_by' => array('order_index' => 'asc'),
                        )
                    )
                )
            )
        )
    );
    

    Using Query Method Chaining Syntax

    (my preferred method over array syntax above)

    $race = Model_Race::query()
        ->related('race.class')
        ->related('race.class.driver)
        ->order_by('race.class.order_index', 'asc')
        ->order_by('race.class.driver.order_index', 'asc')
        ->get();
    

    Build it into the Model

    You can set up the relationships in the model so that this happens by default:

    Race Model:

    protected static $_has_many = [
        'classes' => [
            'conditions' => [
                'order_by' => [
                    'order_index' => 'asc'
                ]
            ]
        ]
    ];
    

    Class Model:

    protected static $_has_many = [
        'drivers' => [
            'conditions' => [
                'order_by' => [
                    'order_index' => 'asc'
                ]
            ]
        ]
    ];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a role inheritance structure where instead of the highest level filtering down,
I'm using MySQL. This is table i have Level Programmingtime Clientname projectid 0 128
I have multiple level parent-child tables(GrandParent, Parent and Child, all many to one relation,
Is it possible to have microsecond level timestamps in log4j logging? This is on
The environment is Oracle 9 & 10. I do not have DBA level access.
I have an double level array. On the first level there are about 10
I have a top level menu in my ShellView and when selecting a sub
I have 10 top-level domains e.g. example1.com, example2.com, example3.com, etc, and each domain has
I have a 2 level nesting objects that i need help with My routes
I have a class level price variable decalred inside a page, like this: public

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.