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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:31:52+00:00 2026-06-07T00:31:52+00:00

In Rails (and even in Doctrine < 2, IIRC) you can specify a default

  • 0

In Rails (and even in Doctrine < 2, IIRC) you can specify a default order for any model. For example, if you tell Rails to always order your customer table by name, Customer.all will always a list of customers ordered by name. It makes an enormous amount of sense.

From what I gather it’s not possible to do this in Doctrine 2. Evidently they want you to create a query instead.

It would be a very DRY, logical and convenient feature to include, and an outstandingly stupid feature to choose to leave out, it seems to me.

I sincerely hope I’m wrong about this option not existing, and before I cry myself to sleep tonight, I wanted to check to see if maybe Doctrine does actually have a way to specify a default order and I just haven’t been able to find it. Can anyone 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-07T00:31:54+00:00Added an answer on June 7, 2026 at 12:31 am

    Whilst you don’t seem to be able to do this for an entire model ala Doctrine 1, you can specify ordering as a notation on the inverse side of a relation:

    // Entity/Category
    
    /**
     * @var ArrayCollection $posts
     *
     * @ORM\OneToMany(targetEntity="Post", mappedBy="category")
     * @ORM\OrderBy({"name" = "ASC"})
     */
    private $posts;
    

    Also, if you’re implementing entity manager services such as those in SonataNewsBundle, you can specify defaults via optional arguments i.e.

    class PostManager extends ModelPostManager
    {
    
        /**
         * {@inheritDoc}
         */
        public function findBy(array $criteria, array $orderBy = array('name' => 'asc'))
        {
            return $this->em->getRepository($this->class)->findBy($criteria, $orderBy);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Rails 3 I use the following helper in order to get a even-odd-coloured
Autotest broke with rspec-rails 2.2.1 update. Now I can't get it working again.. .even
The question says it all. I can't seem to find any recent rails tutorials
In rails I know you can do <tr class=<%= cycle(even, odd) %>> to cycle
some books or even the rails api uses form_for ... ... submit_tag ... end
At even moderate a request volume, the rails log in 3.2.x writes to the
Rails question. The default behavior for error validation is to fieldWithError-styled div around the
When I try to run even simple rails commands such as: rails -h I
I'm building a Rails application using Devise. Devise is all set up even omniauth.
My 3.1.3 rails app takes quite a while to start up, and even running

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.