Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-postgres-array/activerecord.rb

Instance Method Summary collapse

Instance Method Details

#arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/activerecord-postgres-array/activerecord.rb', line 8

def arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
  attrs      = {}
  klass      = self.class
  arel_table = klass.arel_table

  attribute_names.each do |name|
    if (column = column_for_attribute(name)) && (include_primary_key || !column.primary)
      if include_readonly_attributes || !self.class.readonly_attributes.include?(name)
        value = read_attribute(name)
        if column.type.to_s =~ /_array$/ && value && value.is_a?(Array)
          value = value.to_postgres_array(new_record?)
        elsif defined?(::Hstore) && column.type == :hstore && value && value.is_a?(Hash)
          value = value.to_hstore
        elsif klass.serialized_attributes.include?(name)
          value = @attributes[name].serialized_value
        end
        attrs[arel_table[name]] = value
      end
    end
  end

  attrs
end