Skip to content

Commit

Permalink
Merge pull request rails#53436 from baarde/deserialize-auto-populated…
Browse files Browse the repository at this point in the history
…-columns

Deserialize auto populated columns on Active Record object creation
  • Loading branch information
kamipo authored Oct 30, 2024
2 parents 8fded65 + fdfe0fb commit 0e3e0d1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def _create_record(attribute_names = self.attribute_names)
)

returning_columns.zip(returning_values).each do |column, value|
_write_attribute(column, value) if !_read_attribute(column)
_write_attribute(column, type_for_attribute(column).deserialize(value)) if !_read_attribute(column)
end if returning_values
end

Expand Down
2 changes: 2 additions & 0 deletions activerecord/test/cases/persistence_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def test_fills_auto_populated_columns_on_creation
assert_not_nil record.modified_time_without_precision
assert_not_nil record.modified_time_function

assert_equal "A", record.binary_default_function

if supports_identity_columns?
klass = Class.new(ActiveRecord::Base) do
self.table_name = "postgresql_identity_table"
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/schema/postgresql_specific_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
t.string :char2, limit: 50, default: "a varchar field"
t.text :char3, default: "a text field"
t.bigint :bigint_default, default: -> { "0::bigint" }
t.binary :binary_default_function, default: -> { "convert_to('A', 'UTF8')" }
t.text :multiline_default, default: "--- []
"
Expand Down

0 comments on commit 0e3e0d1

Please sign in to comment.