Skip to content

Commit

Permalink
Support change_Table
Browse files Browse the repository at this point in the history
  • Loading branch information
masterkain committed Aug 7, 2012
1 parent ef99da0 commit 2e447b0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/activerecord-postgres-array/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ def quote_with_array(value, column = nil)
alias_method_chain :quote, :array
end

class Table
# Adds array type for migrations. So you can add columns to a table like:
# create_table :people do |t|
# ...
# t.string_array :real_energy
# t.decimal_array :real_energy, :precision => 18, :scale => 6
# ...
# end
PostgreSQLAdapter::POSTGRES_ARRAY_TYPES.each do |column_type|
define_method("#{column_type}_array") do |*args|
options = args.extract_options!
base_type = @base.type_to_sql(column_type.to_sym, options[:limit], options[:precision], options[:scale])
column_names = args
column_names.each { |name| column(name, "#{base_type}[]", options) }
end
end
end

class TableDefinition
# Adds array type for migrations. So you can add columns to a table like:
# create_table :people do |t|
Expand Down

0 comments on commit 2e447b0

Please sign in to comment.