Module: ActiveRecord::Extensions::FinderOptions::HavingOptionBackCompatibility::ClassMethods

Defined in:
lib/ar-extensions/finder_options.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#add_group!(sql, group_options, scope = :auto) ⇒ Object

:nodoc:



256
257
258
259
260
261
262
263
# File 'lib/ar-extensions/finder_options.rb', line 256

def add_group!(sql, group_options, scope = :auto)#:nodoc:
  group, having = if group_options.is_a?(Hash) && group_options.has_key?(:group)
    [group_options[:group] , group_options[:having]]
  else
    [group_options, nil]
  end
  add_group_with_having!(sql, group, having, scope)
end

#add_group_with_having!(sql, group, having, scope = :auto) ⇒ Object

add_group! in version 2.3 adds having already copy that implementation



243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/ar-extensions/finder_options.rb', line 243

def add_group_with_having!(sql, group, having, scope =:auto)#:nodoc:
  if group
    sql << " GROUP BY #{group}"
    sql << " HAVING #{sanitize_sql(having)}" if having
  else
    scope = scope(:find) if :auto == scope
    if scope && (scoped_group = scope[:group])
      sql << " GROUP BY #{scoped_group}"
      sql << " HAVING #{sanitize_sql(scope[:having])}" if scope[:having]
    end
  end
end

#options_with_group(options) ⇒ Object

:nodoc:



265
266
267
268
269
270
271
# File 'lib/ar-extensions/finder_options.rb', line 265

def options_with_group(options)#:nodoc:
  if options[:group]
    options.merge(:group => {:group => options[:group], :having => options[:having]})
  else
    options
  end
end