From 5e223b9201c38dc4048db84652da3870fbfe98de Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 6 Mar 2014 15:36:49 -0300 Subject: [PATCH] rails3: count over queries with includes does not work --- app/models/profile_list_block.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index 7c7f271..b6d1a0d 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -19,10 +19,10 @@ class ProfileListBlock < Block visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment]) if !prioritize_profiles_with_image result = visible_profiles.all(:limit => limit, :order => 'updated_at DESC').sort_by{ rand } - elsif visible_profiles.with_image.count >= limit + elsif profiles.visible.with_image.count >= limit result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand } else - result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand } + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } end result.slice(0..limit-1) end -- libgit2 0.21.2