Re: [Rails-core] Error in ActiveRecord::Associations::AliasTracker when using subquery

63 views
Skip to first unread message

Richard Schneeman

unread,
Dec 23, 2012, 12:10:39 PM12/23/12
to rubyonra...@googlegroups.com
Can you open up a github issue for this? Also include the active record code that was used to generate the error, please try with Active Record 3.2.9 to make sure the bug hasn't been fixed there already. Please re-write any custom active record methods such as `tagged_with` with the plain old active record, to clearly demonstrate how to reproduce the error with only active record.


Github issues is the best place for bug reports.

-- 
Richard Schneeman

On Sunday, December 23, 2012 at 8:22 AM, Manuel Meurer wrote:

Hi all,

I encountered an error in ActiveRecord when using subqueries.

NoMethodError: undefined method `left' for :count:Symbol
# /Users/me/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/alias_tracker.rb:64:in `block in initial_count_for'

(See the full stack trace here: https://gist.github.com/4363280)

This is the offending SQL query:

SELECT "taggable_models".* FROM (SELECT count("tags"."id") AS tags_count, taggable_models.* FROM "taggable_models" INNER JOIN "taggings" ON "taggings"."taggable_id" = "taggable_models"."id" AND "taggings"."taggable_type" = 'TaggableModel' INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" WHERE "tags"."name" IN ('foo') GROUP BY "taggable_models"."id", "taggable_models"."user_id", "taggable_models"."name", "taggable_models"."type", "taggable_models"."foo" ORDER BY tags_count desc) taggable_models

Can anyone see something crazy with this immediately?
Is the "SELECT count("tags"."id") AS tags_count, taggable_models.* ..."-style subquery bad in general?


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/DJupqZfGhe8J.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.

Manuel Meurer

unread,
Dec 25, 2012, 3:13:58 AM12/25/12
to rubyonra...@googlegroups.com
Ok, will do. Just wanted to check first if this really looks like a error in AR...
Reply all
Reply to author
Forward
0 new messages