Skip to content

Added support for parsing multi-dimensional array string #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/activerecord-postgres-array/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ class TableDefinition
end

class PostgreSQLColumn < Column

#
def type_cast_with_array(val)
if type.to_s =~ /_array$/
base_type = type.to_s.gsub(/_array/, '')
val.nil? ? nil : val.from_postgres_array(base_type.parameterize('_').to_sym)
else
type_cast_without_array(val)
end
end
alias_method_chain :type_cast, :array


# Does the type casting from array columns using String#from_postgres_array or Array#from_postgres_array.
def type_cast_code_with_array(var_name)
if type.to_s =~ /_array$/
Expand Down