deduplicated: undefined method '-@' for []:Array with Rails 6.1 and arrays with default value
Created by: 4ndv
Here's test code:
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "activerecord", "6.1.0"
gem "torque-postgresql"
gem "pg"
end
require "active_record"
require "logger"
ActiveRecord::Base.establish_connection(
adapter: "postgresql",
database: "torque_pg_test",
encoding: "unicode",
host: "localhost",
port: "5432",
password: "postgres",
username: "postgres"
)
ActiveRecord::Schema.define do
drop_table "employees" if table_exists?("employees")
drop_table "projects" if table_exists?("projects")
create_table "employees" do |t|
t.string "name"
t.timestamps
end
create_table "projects" do |t|
t.bigint "employees_ids", array: true, default: []
t.string "title"
t.timestamps
end
end
class Employee < ActiveRecord::Base
end
class Project < ActiveRecord::Base
belongs_to_many :employees, foreign_key: :employees_ids
end
Project.inspect
Notice array: true, default: []
in t.bigint "employees_ids", array: true, default: []
When calling Project.inspect
since Rails 6.1 there is an exception in AR:
lib/active_record/connection_adapters/column.rb:94:in `deduplicated': undefined method `-@' for []:Array (NoMethodError)
Looks like AR now tries to unfreeze @default
, which cannot be done to an Array