Dmitry Suzdalev
2011-Sep-08 08:05 UTC
In Rails 3.1 Model.count() ignores :include - no outer join in generated SQL
Hello! At first I posted this in rubyonrails-talk, but no one there was able to tell me if this is a bug or not (I got only suggestion for workaround). As this looks like 3.1 regression that breaks existing 3.0.10 code I decided to post this here in addition. I''ve upgraded to Rails 3.1 (from 3.0.10), ran my test suite and found this issue: class Trade < ActiveRecord::Base has_many :transaction_trades ..... def Trade.do_something stale_trades = Trade.count(''transaction_trades.id'', :include => :transaction_trades, :group => ''trades.id'') :having => "count_transaction_trades_id = 0") end end Earlier this used to work perfectly, now I get this: Mysql2::Error: Unknown column ''transaction_trades.id'' in ''field list'': SELECT COUNT(transaction_trades.id) AS count_transaction_trades_id, trades.id AS trades_id FROM `trades` GROUP BY trades.id What puzzles me is that no LEFT OUTER JOIN on transaction_trades is present in generated SQL - that''s why things broke. And it was there in 3.0.10, so table got joined and this code was perfectly working. Any hints what''s wrong here? Why is :include => :transaction_trades seems to be ignored? -- 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/-/QuqmFOA_RhAJ. 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.
Anatoliy Lysenko
2011-Sep-08 15:15 UTC
Re: In Rails 3.1 Model.count() ignores :include - no outer join in generated SQL
Hi, Here is pull request for this bug https://github.com/rails/rails/pull/2896. Thanks, Anatoliy On 8 September 2011 11:05, Dmitry Suzdalev <dimsuz@gmail.com> wrote:> Hello! > > At first I posted this in rubyonrails-talk, but no one there was able to > tell me if this is a bug or not (I got only suggestion for workaround). > As this looks like 3.1 regression that breaks existing 3.0.10 code I > decided to post this here in addition. > > I''ve upgraded to Rails 3.1 (from 3.0.10), ran my test suite and found this > issue: > > class Trade < ActiveRecord::Base > has_many :transaction_trades > ..... > > def Trade.do_something > stale_trades = Trade.count(''transaction_**trades.id<http://transaction_trades.id/> > '', > :include => :transaction_trades, > :group => ''trades.id'') > :having => "count_transaction_trades_id = 0") > end > end > > Earlier this used to work perfectly, now I get this: > > Mysql2::Error: Unknown column ''transaction_trades.id'' in ''field list'': > SELECT COUNT(transaction_trades.id) AS count_transaction_trades_id, > trades.id AS trades_id FROM `trades` GROUP BY trades.id > > What puzzles me is that no LEFT OUTER JOIN on transaction_trades is > present in generated SQL - that''s why things broke. > And it was there in 3.0.10, so table got joined and this code was perfectly > working. > Any hints what''s wrong here? Why is :include => :transaction_trades seems > to be ignored? > > -- > 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/-/QuqmFOA_RhAJ. > 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. >-- 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.
Dmitry Suzdalev
2011-Sep-08 20:27 UTC
Re: In Rails 3.1 Model.count() ignores :include - no outer join in generated SQL
On Thursday, September 8, 2011 7:15:31 PM UTC+4, Anatoliy Lysenko wrote:> > Here is pull request for this bug https://github.com/rails/rails/pull/2896 > . >Oh, great, thanks for the heads up! I really know almost nothing about RoR release process, so one more little question: should I expect this fix to be in the next minor release (i.e. 3.1.1) ? Thanks :) Dmitry. -- 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/-/dzZ5lzR-hv8J. 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.
Jon Leighton
2011-Sep-08 21:40 UTC
Re: In Rails 3.1 Model.count() ignores :include - no outer join in generated SQL
On Thu, 2011-09-08 at 13:27 -0700, Dmitry Suzdalev wrote:> On Thursday, September 8, 2011 7:15:31 PM UTC+4, Anatoliy Lysenko > wrote: > Here is pull request for this bug > https://github.com/rails/rails/pull/2896. > > Oh, great, thanks for the heads up! > > > I really know almost nothing about RoR release process, so one more > little question: > should I expect this fix to be in the next minor release (i.e. > 3.1.1) ?We''re aiming to release 3.1.1 on Monday 12th, and if the pull request can be merged before then, it will be. -- http://jonathanleighton.com/
Dmitry Suzdalev
2011-Sep-08 21:42 UTC
Re: In Rails 3.1 Model.count() ignores :include - no outer join in generated SQL
On Friday, September 9, 2011 1:40:10 AM UTC+4, Jon Leighton wrote:> > We''re aiming to release 3.1.1 on Monday 12th, and if the pull request > can be merged before then, it will be. >That would be great! Thank you! :)>-- 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/-/IckwFF1aUwYJ. 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.
Maybe Matching Threads
- In Rails 3.1 Model.count() ignores :include - no outer join in generated SQL
- Can't heal a volume: "Please check if all brick processes are running."
- Can't heal a volume: "Please check if all brick processes are running."
- Newbie question: what to start from?
- Can't heal a volume: "Please check if all brick processes are running."