aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
blob: acb1278499d03be853b1f6b1719d7107600c26d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module ActiveRecord
  module ConnectionAdapters
    # PostgreSQL-specific extensions to column definitions in a table.
    class PostgreSQLColumn < Column #:nodoc:
      attr_reader :array
      alias :array? :array

      def initialize(name, default, cast_type, sql_type = nil, null = true, default_function = nil)
        if sql_type =~ /\[\]$/
          @array = true
          sql_type = sql_type[0..sql_type.length - 3]
        else
          @array = false
        end
        super
      end

      def serial?
        default_function && default_function =~ /\Anextval\(.*\)\z/
      end
    end
  end
end