This project is archived and is in readonly mode.

#5768 ✓stale

A set of includes in active records break when I add an order

Reported by | October 8th, 2010 @ 06:05 AM

I'll give you more context information bellow, but first, let me show you some active records call.

First a simple "let's get a clock":


that works. Then, let's include some associations

    @user.clocks.includes(:users, :runs).find(
    @user.clocks.includes(:users, :runs => :user_runs).find(

all right. Now let's order them:

    @user.clocks.includes(:users, :runs).order("").find(
    @user.clocks.includes(:users, :runs => :user_runs).order("").find(

all work except the last one. The last one throws this error:

    ActiveRecord::ConfigurationError: Association named 'user_runs' was not found; perhaps you misspelled it?

but note that the same includes in the previous set of queries, without the order, worked fine (although I think it was not retrieving :user_runs).

Interestingly enough, if I try to run it with the old syntax:

   @user.clocks.find(, :include => [:users, {:runs => :user_runs}], :order => "")

it doesn't throw an exception.

Is this not a bug? am I missing something?

Comments and changes to this ticket

  • October 8th, 2010 @ 06:09 AM

    This is the relevant context:

    class User < ActiveRecord::Base
      has_and_belongs_to_many :clocks
      has_many :runs, :through => :clocks
      has_many :user_runs
    class Clock < ActiveRecord::Base
      has_and_belongs_to_many :users
      has_many :runs
      # ...
    class Run < ActiveRecord::Base
      belongs_to :clock
      has_many :user_runs
      # ...
    class UserRun < ActiveRecord::Base
      belongs_to :run
      belongs_to :user
      # ...


      create_table "clocks", :force => true do |t|
      create_table "clocks_users", :id => false, :force => true do |t|
        t.integer "clock_id", :null => false
        t.integer "user_id",  :null => false
      create_table "runs", :force => true do |t|
        t.integer  "clock_id"
      create_table "user_runs", :force => true do |t|
        t.integer  "run_id"
        t.integer  "user_id"
      create_table "users", :force => true do |t|


  • Jon Leighton

    Jon Leighton December 21st, 2010 @ 07:50 PM

    • State changed from “new” to “stale”
    • Importance changed from “” to “Low”

    Hi there,

    Thanks for the bug report.

    I've tried out your code against Rails 3.0.3 and cannot reproduce the problem.

    I'm marking as stale, let me know if the problem does still exist and I can re-open.


Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>