Thursday, October 7, 2010

[Rails] Re: Not being able to order by includes on Rails3

Continuing with my investigation I've tried this:

ubiquitous_user.clocks.includes(:runs
=> :user_runs).find_by_id(params[:id])

and I've noticed the queries it's generating doesn't get user_runs at
all.

On Oct 7, 9:51 pm, J. Pablo Fernández <pup...@gmail.com> wrote:
> 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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate