photomix/lib/ext/group_for.rb

13 lines
389 B
Ruby
Raw Normal View History

2012-07-24 23:26:16 +02:00
module Ext
module GroupFor
def self.extended(base)
if (ActiveRecord::Base.connection.adapter_name == 'PostgreSQL')
if base.table_exists?
base.scope :group_for, {:group => base.column_names.map { |col_name| "#{base.table_name}.#{col_name}" }}
end
else
base.scope :group_for, {:group => "#{base.quoted_table_name}.id"}
end
end
end
end