Last active
August 24, 2023 03:47
-
-
Save RichOrElse/c01c74c30766976f5587daaec2179239 to your computer and use it in GitHub Desktop.
ActiveRecord missing methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
scope :subquery_as, ->(name) { unscoped.from(arel.as(name)) } | |
scope :select_with, ->(*fields) { dup.select_with!(*fields) } | |
scope :select_with!, ->(*fields) { self.select_values |= fields.flatten | [table[Arel.star]]; self } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ArelExcept | |
refine ActiveRecord::Relation do | |
def except(other)= unscoped.from arel.except(other.arel).as(table_name) | |
end | |
[NilClass, FalseClass].each do |falsey_type| | |
refine falsey_type do | |
def except(other)= other | |
end | |
end | |
refine Module do | |
def except(other)= all.except other | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment