On Sep 6, 3:51 pm, Dmitry Suzdalev <dim...@gmail.com> wrote:
> So guys, no ideas about this one?
> Why Model.count is completely broken in 3.1 when using :include option?
> (see my original mail for details)
>
>From which version did you upgrade?
Part of the problem with include is that there has (for some years
now) been two different code paths that rails can do down when there
is an :include option, one  that uses joins and one that doesn't.
Rails tries to pick the right one if it things you are references the
joined columns elsewhere in your code, but that detection has never
been 100%

If my memory is correct, the eager_load option forces the use of the
join variant.

Fred


> I consider two possibilities:
> 1) there might be some new option which I need to enable (though strange
> that this was not announced)
> 2) this is some regression specific to Rails 3.1 and I should report this as
> a bug upstream
>
> If this is 2) I guess I should forward this to rails-core mailing list?...
>
>
>
>
>
>
>
> On Monday, September 5, 2011 10:11:24 PM UTC+4, Dmitry Suzdalev wrote:
>
> > Hello!
>
> > Just upgraded to Rails 3.1, ran my test 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.
> > 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: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to