mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
format
avoiding block + return
This commit is contained in:
parent
21462b06e1
commit
83ce8a456f
1 changed files with 9 additions and 8 deletions
|
@ -12,21 +12,22 @@ module Kaminari
|
||||||
# #count overrides the #select which could include generated columns referenced in #order, so skip #order here, where it's irrelevant to the result anyway
|
# #count overrides the #select which could include generated columns referenced in #order, so skip #order here, where it's irrelevant to the result anyway
|
||||||
@total_count ||= begin
|
@total_count ||= begin
|
||||||
c = except(:offset, :limit, :order)
|
c = except(:offset, :limit, :order)
|
||||||
|
|
||||||
# a workaround for 3.1.beta1 bug. see: https://github.com/rails/rails/issues/406
|
# a workaround for 3.1.beta1 bug. see: https://github.com/rails/rails/issues/406
|
||||||
c = c.reorder nil
|
c = c.reorder nil
|
||||||
|
|
||||||
# Remove includes only if they are irrelevant
|
# Remove includes only if they are irrelevant
|
||||||
c = c.except(:includes) unless references_eager_loaded_tables?
|
c = c.except(:includes) unless references_eager_loaded_tables?
|
||||||
|
|
||||||
|
# a workaround to count the actual model instances on distinct query because count + distinct returns wrong value in some cases. see https://github.com/amatsuda/kaminari/pull/160
|
||||||
uses_distinct_sql_statement = c.to_sql =~ /DISTINCT/i
|
uses_distinct_sql_statement = c.to_sql =~ /DISTINCT/i
|
||||||
if uses_distinct_sql_statement
|
if uses_distinct_sql_statement
|
||||||
return c.length
|
c.length
|
||||||
|
else
|
||||||
|
# .group returns an OrderdHash that responds to #count
|
||||||
|
c = c.count
|
||||||
|
c.respond_to?(:count) ? c.count : c
|
||||||
end
|
end
|
||||||
|
|
||||||
# .group returns an OrderdHash that responds to #count
|
|
||||||
c = c.count
|
|
||||||
c.respond_to?(:count) ? c.count : c
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue