ActiveRecord extending scopes but not the base class
module QueryMethods
def initialize_copy(other)
super
@__memo = {} # reset cache on every copy
end
def count_from_schema
@__memo ||= {}
@__memo[:count_from_schema] ||= connection.select_value(%(
SELECT TABLE_ROWS
FROM information_schema.tables
WHERE table_schema = DATABASE()
AND table_name = '#{table_name}'
).squish)
end
end
def self.default_scoped(scope = relation)
super.extending(QueryMethods)
end