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

Support enums and scopes on super class in STI models #287

Open
tk0miya opened this issue Nov 13, 2024 · 0 comments
Open

Support enums and scopes on super class in STI models #287

tk0miya opened this issue Nov 13, 2024 · 0 comments

Comments

@tk0miya
Copy link
Collaborator

tk0miya commented Nov 13, 2024

ActiveRecord supports STI (Single Table Inheritance) via class inheritation.
If the parent class of the STI model has enum definitions, scopes, and so on, the child classes can use them also.

Example:

class User < ActiveRecord::Base
  scope :active, -> { where(is_active: 1) }
end

class AdminUser < User
end

AdminUser.active  # scopes defined in the parent class are available in the child classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant