1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test
Ryuta Kamizono 8c793aa88b Allow attribute's default to be configured but keeping its own type
```ruby
class Post < ActiveRecord::Base
  attribute :written_at, default: -> { Time.now.utc }
end

# Rails 6.0
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>

# Rails 6.1
Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
```

This is an alternative of #39797.

Context https://github.com/rails/rails/pull/39797#issuecomment-655191817.

If people intend to override the existing type on the attribute, usually
an overriding type is explicitly specified, so I agree that the current
behavior (drop existing type information if type is omitted) is
practically quite useless, and it is almost like a bug in that there is
no way to override just the default.

So I'd like to change the current behavior on existing attributes
without a deprecation as a fix.

Closes #39797.

See also https://github.com/kufu/activerecord-bitemporal/pull/57.
2020-07-14 07:02:57 +09:00
..
active_record/connection_adapters Deduplicate various Active Record schema cache structures 2019-06-03 13:31:42 +02:00
assets
cases Allow attribute's default to be configured but keeping its own type 2020-07-14 07:02:57 +09:00
fixtures Resolve attribute alias for counter cache column 2020-07-06 12:06:01 +09:00
migrations
models Resolve attribute alias for counter cache column 2020-07-06 12:06:01 +09:00
schema Resolve attribute alias for counter cache column 2020-07-06 12:06:01 +09:00
support Add Active Record Marshal forward compatibility tests 2020-07-02 14:11:51 +02:00
config.example.yml Remove more code for unsupported frontbase and ibm_db adapters 2020-04-12 11:45:28 +09:00
config.rb