I have the following expression:
user.clocks.includes(:runs
=> :user_runs).includes(:users).find_by_id(params[:id])
which seems to work fine. But when I add an orders, like this:
user.clocks.includes(:runs
=>
:user_runs).includes(:users).orders(“users.names”).find_by_id(params[:id])
it breaks with the following error:
ActiveRecord::ConfigurationError: Association named 'user_runs'
was not found; perhaps you misspelled it?
app/controllers/clocks_controller.rb:19:in show' test/functional/clocks_controller_test.rb:21:in
__bind_1286475263_942556’
Any ideas why?
The model looks like this:
class Clock < ActiveRecord::Base
has_and_belongs_to_many :users
has_many :runs
end
class Run < ActiveRecord::Base
belongs_to :clock
has_many :user_runs
has_many :users, :through => :user_runs
end
class UserRun < ActiveRecord::Base
belongs_to :run
belongs_to :user
end