mirror of https://github.com/rails/rails
Merge pull request #51483 from JoeDupuis/add-date-text-decoder-postgresql-adapter
Add a Date decoder to the pg adapter
This commit is contained in:
commit
6a38d3ac6c
|
@ -1,3 +1,13 @@
|
|||
* `PostgreSQLAdapter` now decodes columns of type date to `Date` instead of string.
|
||||
|
||||
Ex:
|
||||
```ruby
|
||||
ActiveRecord::Base.connection
|
||||
.select_value("select '2024-01-01'::date").class #=> Date
|
||||
```
|
||||
|
||||
*Joé Dupuis*
|
||||
|
||||
* Strict loading using `:n_plus_one_only` does not eagerly load child associations.
|
||||
|
||||
With this change, child associations are no longer eagerly loaded, to
|
||||
|
|
|
@ -1159,6 +1159,7 @@ module ActiveRecord
|
|||
"bool" => PG::TextDecoder::Boolean,
|
||||
"timestamp" => PG::TextDecoder::TimestampUtc,
|
||||
"timestamptz" => PG::TextDecoder::TimestampWithTimeZone,
|
||||
"date" => PG::TextDecoder::Date,
|
||||
}
|
||||
|
||||
known_coder_types = coders_by_name.keys.map { |n| quote(n) }
|
||||
|
|
|
@ -39,4 +39,10 @@ class PostgresqlDateTest < ActiveRecord::PostgreSQLTestCase
|
|||
topic = Topic.create!(last_read: date)
|
||||
assert_equal date, Topic.find(topic.id).last_read
|
||||
end
|
||||
|
||||
def test_date_decoder
|
||||
date = ActiveRecord::Base.connection.select_value("select '2024-01-01'::date")
|
||||
assert_equal Date.new(2024, 01, 01), date
|
||||
assert_equal Date, date.class
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue