Skip to content

Commit ef299a5

Browse files
Replace :disabled with nil
If there's a column named `disabled`, we'll still raise `ActiveRecord::SubclassNotFound`. Setting `inheritance_column` to `nil` works though. I had mistakenly thought `:disabled` was the correct way to disable STI, since this is what is done in [some tests][]. ```ruby Schema: cogs[ id, type, disabled, created_at, updated_at ] class Cog < ApplicationRecord self.inheritance_column = nil end Cog.create! type: "Sprocket", disabled: true => #<Cog type: "Sprocket", disabled: "t"> ``` [some tests]: https://github.com/rails/rails/blob/a4751751bced209550f38f48bb58b64406d475a5/activerecord/test/models/post.rb#L231
1 parent fcc000c commit ef299a5

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

activerecord/lib/active_record/inheritance.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def sti_class_for(type_name)
204204
"Please rename this column if you didn't intend it to be used for storing the inheritance class " \
205205
"or overwrite #{name}.inheritance_column to use another column for that information. " \
206206
"If you wish to disable single-table inheritance for #{name} set " \
207-
"#{name}.inheritance_column to :disabled."
207+
"#{name}.inheritance_column to nil"
208208
end
209209

210210
# Returns the value to be stored in the polymorphic type column for Polymorphic Associations.

activerecord/lib/active_record/model_schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ module ModelSchema
148148
# self.inheritance_column = 'zoink'
149149
#
150150
# If you wish to disable single-table inheritance altogether you can set
151-
# +inheritance_column+ to +:disabled+
151+
# +inheritance_column+ to +nil+
152152
#
153-
# self.inheritance_column = :disabled
153+
# self.inheritance_column = nil
154154

155155
##
156156
# :singleton-method: inheritance_column=

guides/source/association_basics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,12 +2937,12 @@ There may be cases (like when working with a legacy database) where you need to
29372937
disable Single Table Inheritance altogether. Otherwise, you'll raise
29382938
[`ActiveRecord::SubclassNotFound`][].
29392939

2940-
This can be achieved by setting the [inheritance_column][] to `:disabled`.
2940+
This can be achieved by setting the [inheritance_column][] to `nil`.
29412941

29422942
```ruby
29432943
# Schema: vehicles[ id, type, created_at, updated_at ]
29442944
class Vehicle < ApplicationRecord
2945-
self.inheritance_column = :disabled
2945+
self.inheritance_column = nil
29462946
end
29472947

29482948
Vehicle.create!(type: "Car")

0 commit comments

Comments
 (0)