This project is archived and is in readonly mode.
has_many :through + scope + empty? fails in 2.3.2 (but not 2.3.0)
Reported by Henrik Nyh | March 22nd, 2009 @ 01:28 PM | in 2.x
A Post has_many Tags through Taggings.
Tag has this named scope:
named_scope :by_name, { :order => 'name ASC' }
In Rails 2.2.2 and 2.3.0, this worked fine:
a_post.tags.by_name.empty?
It generates a query like
SELECT count(*) AS count_all FROM `tags` INNER JOIN `taggings` ON `tags`.id = `taggings`.tag_id WHERE ((`taggings`.post_id = 881129040))
In Rails 2.3.2, it breaks:
SQL (0.0ms) Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) AS count_tags_all FROM `tags` INNER JOIN `taggings` ON `tags`.id = `taggings`' at line 1: SELECT count(`tags`.*) AS count_tags_all FROM `tags` INNER JOIN `taggings` ON `tags`.id = `taggings`.tag_id WHERE (((`taggings`.post_id = 881129040)) AND ((`taggings`.post_id = 881129040)))
The (invalid) query generated here is
SELECT count(`tags`.*) AS count_tags_all FROM `tags` INNER JOIN `taggings` ON `tags`.id = `taggings`.tag_id WHERE (((`taggings`.post_id = 881129040)) AND ((`taggings`.post_id = 881129040)))
I'm sorry I don't have more details or a failing spec yet. Figured I'd report the issue for now, and possibly dig into later.
Comments and changes to this ticket
-
Henrik Nyh March 22nd, 2009 @ 02:02 PM
Probably related:
p = Post.last t = Tag.last p.tags << t
gives
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) AS count_posts_all FROM `posts` INNER JOIN `taggings` ON `posts`.id = `taggin' at line 1: SELECT count(`posts`.*) AS count_posts_all FROM `posts` INNER JOIN `taggings` ON `posts`.id = `taggings`.post_id WHERE (((posts.published_at IS NOT NULL) AND ((`taggings`.tag_id = 834120776))) AND ((`taggings`.tag_id = 834120776)))
Where the invalid query is
SELECT count(`posts`.*) AS count_posts_all FROM `posts` INNER JOIN `taggings` ON `posts`.id = `taggings`.post_id WHERE (((posts.published_at IS NOT NULL) AND ((`taggings`.tag_id = 834120776))) AND ((`taggings`.tag_id = 834120776)))
-
Steven Soroka March 26th, 2009 @ 04:03 PM
- State changed from new to resolved
This bug was introduced by commit 6543426... Ensure calculations respect scoped :select [#1334 state:resolved]
-
Steven Soroka March 26th, 2009 @ 04:05 PM
- State changed from resolved to new
uh. that was not supposed to change the state. wonder if this will change it back: [#2310 state:new]
-
Steve St. Martin April 15th, 2010 @ 11:53 PM
- Assigned user set to Ryan Bigg
duplicates #2189, can be marked as duplicate
-
Ryan Bigg April 16th, 2010 @ 01:24 AM
- State changed from new to duplicate
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Tags
Referenced by
- 2310 has_many :through + scope + empty? fails in 2.3.2 (but not 2.3.0) uh. that was not supposed to change the state. wonder if ...
- 1334 Count calculations should respect scoped selects this patch caused a bug with scopes and has-many-through'...
- 2507 .count on a named_scope on a has_many association throws error Sorry, just realized this is a duplicate bug report, with...