Skip to content

Commit

Permalink
Improve the documentation for ActiveRecord::Inheritance#base_class
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewn617 committed Aug 23, 2023
1 parent ed5af00 commit 4627995
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions activerecord/lib/active_record/inheritance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,24 @@ def finder_needs_type_condition? # :nodoc:
:true == (@finder_needs_type_condition ||= descends_from_active_record? ? :false : :true)
end

# Returns the class descending directly from ActiveRecord::Base, or
# an abstract class, if any, in the inheritance hierarchy.
# Returns the first class in the inheritance hierarchy that descends from either an
# abstract class or from <tt>ActiveRecord::Base</tt>.
#
# If A extends ActiveRecord::Base, A.base_class will return A. If B descends from A
# through some arbitrarily deep hierarchy, B.base_class will return A.
# Consider the following behaviour:
#
# If B < A and C < B and if A is an abstract_class then both B.base_class
# and C.base_class would return B as the answer since A is an abstract_class.
# class ApplicationRecord < ActiveRecord::Base
# self.abstract_class = true
# end
# class Shape < ApplicationRecord
# self.abstract_class = true
# end
# Polygon = Class.new(Shape)
# Square = Class.new(Polygon)
#
# ApplicationRecord.base_class # => ApplicationRecord
# Shape.base_class # => Shape
# Polygon.base_class # => Polygon
# Square.base_class # => Polygon
attr_reader :base_class

# Returns whether the class is a base class.
Expand Down

0 comments on commit 4627995

Please sign in to comment.