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
Conversation
## | ||
# :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' |
There was a problem hiding this comment.
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=
?
There was a problem hiding this comment.
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=
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
3a52873
to
f267de4
Compare
f267de4
to
bc4e77a
Compare
Thank you, @jean-francois-labbe! 😃 (Backported to |
Makes the inheritance_column api documentation visible [ci-skip] (cherry picked from commit 09362a8)
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
With this change it yields