Skip to content

Commit 2c57ec6

Browse files
committed
Include ActiveModel::API in ActiveRecord::Base
`ActiveRecord::Base` does not (and has never) inherit from `ActiveModel::Model`. `ActiveModel::API` was introduced in as an extraction from `ActiveModel::Model`. At that time (Sep 15, 2021), it was included back into `ActiveModel::Model`, but was never included in `ActiveRecord` at all. The intent communicated around the introduction of `ActiveModel::API` stated: > By moving `ActiveModel::Model`'s implementation to a new > `ActiveModel::API` we keep a definition of the minimum API to talk with > Action Pack and Action View. Active Record is also designed to integrate with Action Pack and Action View. It already does (and its integration predates `ActiveModel::API` by more than a decade). It's integration is powered by including and extending the same set of foundational modules, with some database-specific overrides. This commit adds an `include ActiveModel::API` statement to `ActiveRecord::Base`, then re-structures those overrides to comply with the new module resolution order. [c477d95]: rails@c477d95
1 parent 633eb5a commit 2c57ec6

File tree

6 files changed

+6
-8
lines changed

6 files changed

+6
-8
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Include `ActiveModel::API` in `ActiveRecord::Base`
2+
3+
*Sean Doyle*
4+
15
* Ensure `#signed_id` outputs `url_safe` strings.
26

37
*Jason Meller*

activerecord/lib/active_record/attribute_assignment.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
module ActiveRecord
44
module AttributeAssignment
5-
include ActiveModel::AttributeAssignment
6-
75
private
86
def _assign_attributes(attributes)
97
multi_parameter_attributes = nested_parameter_attributes = nil

activerecord/lib/active_record/base.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ module ActiveRecord # :nodoc:
280280
# So it's possible to assign a logger to the class through <tt>Base.logger=</tt> which will then be used by all
281281
# instances in the current object space.
282282
class Base
283-
extend ActiveModel::Naming
283+
include ActiveModel::API
284284

285285
extend ActiveSupport::Benchmarkable
286286
extend ActiveSupport::DescendantsTracker
@@ -304,7 +304,6 @@ class Base
304304
include Scoping
305305
include Sanitization
306306
include AttributeAssignment
307-
include ActiveModel::Conversion
308307
include Integration
309308
include Validations
310309
include CounterCache

activerecord/lib/active_record/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def initialize(attributes = nil)
428428
init_internals
429429
initialize_internals_callback
430430

431-
assign_attributes(attributes) if attributes
431+
super
432432

433433
yield self if block_given?
434434
_run_initialize_callbacks

activerecord/lib/active_record/translation.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
module ActiveRecord
44
module Translation
5-
include ActiveModel::Translation
6-
75
# Set the lookup ancestors for ActiveModel.
86
def lookup_ancestors # :nodoc:
97
klass = self

activerecord/lib/active_record/validations.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def initialize(record = nil)
3939
# {new_record?}[rdoc-ref:Persistence#new_record?].
4040
module Validations
4141
extend ActiveSupport::Concern
42-
include ActiveModel::Validations
4342

4443
# The validation process on save can be skipped by passing <tt>validate: false</tt>.
4544
# The validation context can be changed by passing <tt>context: context</tt>.

0 commit comments

Comments
 (0)