We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Today I work with a model, which is defined default scope. But i need to get the data which including the inactive status.
inactive
module SuperStore class StoreItem < ApplicationRecord # Enums enum status: [:inactive, :active], _suffix: true # Scopes default_scope { active_status.order(:type, updated_at: :desc) } end end
Override by adding this.
scope :with_inactive_status, -> { unscope(where: :status) }
Then use it as:
def set_resource @store_item = StoreItem.with_inactive_status.find(params[:id]) end
Is the default scope good? https://coderwall.com/p/khht6a/beware-of-using-default-scope
We should not use unscoped, define a scope in model to make it clearer https://stackoverflow.com/questions/25087336/why-is-using-the-rails-default-scope-often-recommend-against https://stackoverflow.com/questions/9968738/how-to-bypass-default-scope https://stackoverflow.com/questions/1834159/overriding-a-rails-default-scope/4166950#4166950 https://qiita.com/yokochi@github/items/730418b0c7f36ded5b5f
unscoped
scope
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Problem:
Today I work with a model, which is defined default scope.
But i need to get the data which including the
inactive
status.Solution:
Override by adding this.
Then use it as:
Lesson:
Is the default scope good?
https://coderwall.com/p/khht6a/beware-of-using-default-scope
We should not use
unscoped
, define ascope
in model to make it clearerhttps://stackoverflow.com/questions/25087336/why-is-using-the-rails-default-scope-often-recommend-against
https://stackoverflow.com/questions/9968738/how-to-bypass-default-scope
https://stackoverflow.com/questions/1834159/overriding-a-rails-default-scope/4166950#4166950
https://qiita.com/yokochi@github/items/730418b0c7f36ded5b5f
The text was updated successfully, but these errors were encountered: