-
-
Save trushkevich/3faed6a1f96ed1b9837e to your computer and use it in GitHub Desktop.
Revisions
-
trushkevich renamed this gist
Jun 3, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
trushkevich revised this gist
Jun 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ module ExtensionMethods def count(*args) scope = except(:select).select("1") query = "SELECT count(*) AS count_all FROM (#{scope.to_sql}) x" ActiveRecord::Base.connection.execute(query).first.first end end -
mrbrdo revised this gist
May 30, 2013 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,4 +19,6 @@ def returns_count_sum ActiveRecord::Base.send :include, ActiveRecordGroupCount # usage: # Model.group(:something).returns_count_sum.count # faster Kaminari pagination: # Model.returns_count_sum.page(1).per(10).total_pages -
mrbrdo revised this gist
May 30, 2013 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,17 @@ module ActiveRecordGroupCount extend ActiveSupport::Concern module ExtensionMethods def count(*args) scope = except(:select).select("1") query = "SELECT count(*) AS count_all FROM (#{scope.to_sql}) x" ActiveRecord::Base.connection.execute(query).first.try(:[], "count_all").to_i end end module ClassMethods def returns_count_sum scoped.extending(ExtensionMethods) end end end -
mrbrdo renamed this gist
May 30, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mrbrdo created this gist
May 30, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ module ActiveRelationGroupCount def count(*args) scope = except(:select).select("1") query = "SELECT count(*) AS count_all FROM (#{scope.to_sql}) x" ActiveRecord::Base.connection.execute(query).first.try(:[], "count_all").to_i end end module ActiveRecordGroupCount extend ActiveSupport::Concern module ClassMethods def returns_count_sum scoped.extending(ActiveRelationGroupCount) end end end ActiveRecord::Base.send :include, ActiveRecordGroupCount # usage: # Model.group(:something).returns_count_sum.count