Created
April 24, 2024 18:56
-
-
Save kaspth/7263e05d19989ce10e28553ff6bcf483 to your computer and use it in GitHub Desktop.
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 ActiveRecord::Relation::Loaded < Data.define(:records) | |
def where(**conditions) | |
records = @records.dup | |
conditions.each do |key, value| | |
records.select! { |record| record.send(key) == value } | |
end | |
with(records:) | |
end | |
# Not sure how to maintain the order of the passed in keys? | |
# Also need to parse SQL statements | |
def order(*ascending_clauses, **clauses) | |
clauses = ascending_clauses.chain(clauses).map do |key, direction = :asc| | |
end | |
with(records: records.sort_by { clauses.call _1 }) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment