Commit 5e223b9201c38dc4048db84652da3870fbfe98de

Authored by Victor Costa
1 parent f7be1cc6

rails3: count over queries with includes does not work

Showing 1 changed file with 2 additions and 2 deletions   Show diff stats
app/models/profile_list_block.rb
... ... @@ -19,10 +19,10 @@ class ProfileListBlock < Block
19 19 visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
20 20 if !prioritize_profiles_with_image
21 21 result = visible_profiles.all(:limit => limit, :order => 'updated_at DESC').sort_by{ rand }
22   - elsif visible_profiles.with_image.count >= limit
  22 + elsif profiles.visible.with_image.count >= limit
23 23 result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand }
24 24 else
25   - result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand }
  25 + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
26 26 end
27 27 result.slice(0..limit-1)
28 28 end
... ...