Hi, I've always had problems when I used a "includes" in a default
scope with methods such as "count" or "built", try to remove the
"includes(:campaigns)", of course the ('campaigns.inactive = ?',
false) do not work.

You can use a specific scope like :actives, where('campaigns.inactive
= ?', false)

¿A better solution?

2011/6/13 Jon Leighton <[email protected]>:
> Please could you file this as an issue on Github, with a full example of
> the models you are using?
>
> Jon
>
> On Sun, 2011-06-12 at 14:52 -0700, jgelo wrote:
>> I've run into an issue in Rails 3.1 RC4 where the count query is
>> failing because of a default_scope.  The scope has an include and a
>> condition on the included association but count is dropping the
>> include.  Here's what it looks like -
>>
>> default_scope where('campaigns.inactive = ?',
>> false).order('funds.name').includes(:campaigns)
>>
>> Rails 3.1 RC4 -
>>
>> ruby-1.9.2-p180 :001 > Fund.count
>> [2011-06-12 14:35:43 | WARN   | n/a | named_scope.rb:175:in
>> `valid_scope_name?']
>> > Creating scope :all. Overwriting existing method Fund.all.
>> [2011-06-12 14:35:43 | DEBUG  | n/a | log_subscriber.rb:105:in `debug']
>> >    (0.4ms)  SELECT COUNT(*) FROM "funds" WHERE (campaigns.inactive = 'f')
>> ActiveRecord::StatementInvalid: PGError: ERROR:  missing FROM-clause
>> entry for table "campaigns"
>> LINE 1: SELECT COUNT(*) FROM "funds"  WHERE (campaigns.inactive =
>> 'f...
>>
>>
>> Rails 3.0.8 -
>>
>> ruby-1.9.2-p180 :001 > Fund.count
>>  => 1
>>
>> SQL (43.8ms)  SELECT COUNT(DISTINCT "funds"."id") FROM "funds" LEFT
>> OUTER JOIN "campaigns" ON "campaigns"."fund_id" = "funds"."id" WHERE
>> (campaigns.inactive = 'f')
>>
>
> --
> http://jonathanleighton.com/
>



-- 
http://flowersinspace.com
http://jose.gr

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to