Skip to content

There are cases where default value is not set in STI since Rails 8.0.1 #100

@k-tsuchiya-jp

Description

@k-tsuchiya-jp

Steps to reproduce

$ rails _8.0.1_ new hoge_app
$ cd hoge_app
$ rails g model vehicle type:string color:string price:integer release_date:datetime
$ rails g model car --parent=Vehicle
$ rails db:migrate
# Gemfile
source "https://rubygems.org"

gem "rails", "~> 8.0.1"
gem "default_value_for"

# app/models/vehicle.rb
class Vehicle < ApplicationRecord
  default_value_for :color, "black"
end

# app/models/car.rb
class Car < Vehicle
  default_value_for :price, 100
  default_value_for :release_date, DateTime.now
end
$ bundle install
$ rails r 'p Car.new'
#<Car id: nil, type: "Car", color: "black", price: nil, release_date: "2024-12-26 04:30:36.002660000 +0000", created_at: nil, updated_at: nil>

Expected behavior

$ rails r 'p Car.new'
#<Car id: nil, type: "Car", color: "black", price: 100, release_date: "2024-12-26 04:30:36.002660000 +0000", created_at: nil, updated_at: nil>

Actual behavior

  • price is set to nil

System configuration

Rails version: 8.0.1
Ruby version: 3.3.5
DefaultValueFor version: 4.1.0

Additional information

It seems to be caused by the modification of class_attribute method in Rails 8.0.1.
rails/rails#53640

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions