Manuel Meurer
2012-Dec-23 13:22 UTC
Error in ActiveRecord::Associations::AliasTracker when using subquery
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? (from https://github.com/bradphelan/rocket_tag/issues/47) -- 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Richard Schneeman
2012-Dec-23 17:10 UTC
Re: Error in ActiveRecord::Associations::AliasTracker when using subquery
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 http://heroku.com @schneems (http://twitter.com/schneems) 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? > > (from https://github.com/bradphelan/rocket_tag/issues/47) > > -- > 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 rubyonrails-core@googlegroups.com (mailto:rubyonrails-core@googlegroups.com). > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com (mailto:rubyonrails-core+unsubscribe@googlegroups.com). > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Manuel Meurer
2012-Dec-25 08:13 UTC
Re: Error in ActiveRecord::Associations::AliasTracker when using subquery
Ok, will do. Just wanted to check first if this really looks like a error in AR... On Sunday, December 23, 2012 6:10:39 PM UTC+1, richard schneeman wrote:> > 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 > http://heroku.com > @schneems <http://twitter.com/schneems> > > 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? > > (from https://github.com/bradphelan/rocket_tag/issues/47) > > -- > 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<javascript:> > . > To unsubscribe from this group, send email to > rubyonrails-co...@googlegroups.com <javascript:>. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > > >-- 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/-/63Y0VGAjXwYJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.