Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes the inheritance_column api documentation visible [ci-skip] #45382

Merged
merged 1 commit into from Jun 20, 2022

Conversation

jean-francois-labbe
Copy link
Contributor

Summary

This PR makes the inheritance_column searchable in the api documentation.

When trying to configure Single table inheritance for a model. I knew I could configure the column name. I couldn't find it in the api search bar. I expected to find it using the inheritance word.
The inheritance_column is mentioned here https://api.rubyonrails.org/classes/ActiveRecord/Inheritance.html.

The current 'inheritance' search yields
image

With this change it yields
image

Comment on lines 129 to 141
##
# :singleton-method: inheritance_column=
# :call-seq: inheritance_column=(column)
#
# Defines the name of the table column which will store the class name on single-table
# inheritance situations.
#
# The default inheritance column name is +type+, which means it's a
# reserved word inside Active Record. To be able to use single-table
# inheritance with another column name, or to use the column +type+ in
# your own model for something else, you can set +inheritance_column+:
#
# self.inheritance_column = 'zoink'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only documents the setter. Should we split this into getter and setter documentation, a la implicit_order_column and implicit_order_column=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split the documentation one part for inheritance_column and another forinheritance_column=

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a quick question about the way we declare the inheritance_column.
It requires the use to the self keyword.
When comparing how we declare associations, the has_many, belongs_to do not require self keyword.

class Car < ApplicationRecord
  self.inheritance_column = 'car_type'

  has_many :parts
end

Is there a reason why we need to write it this waysself.inheritance_column = 'car_type' instead of inheritance_column :car_type ?

class Car < ApplicationRecord
  inheritance_column :car_type

  has_many :parts
end

I'd like to understand the reason behind this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand your question.

Are you asking why we need to write self.? That is necessary because inheritance_column is implemented as a class attribute. If we wrote just inheritance_column = "foo", it would set a local variable inheritance_column instead of MyClass.inheritance_column. (It's the same as with attr_writer.)

Or are you asking why inheritance_column was implemented as a class attribute instead of another way? In that case, I do not have an objective answer.

@jonathanhefner
Copy link
Member

jonathanhefner commented Jun 20, 2022

Thank you, @jean-francois-labbe! 😃

(Backported to 7-0-stable.)

jonathanhefner added a commit to jonathanhefner/rails that referenced this pull request Jun 25, 2022
Makes the inheritance_column api documentation visible [ci-skip]

(cherry picked from commit 09362a8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants