-
-
Save paulcsmith/5b7ce214219021d9b2f6a350cc90d37a 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
left_outer_joins(:schedule).where( | |
"schedules.id IS NULL OR schedules.starts_on <= ?", | |
Date.current, | |
) | |
left_out_joins_schedule.where(&.id == nil).or_where(&.starts_on <= Date.current).where(&.name.lower == "something") | |
.where(&.rating.avg > 5) | |
class UserRows | |
def where(&block) | |
@wheres << yield UserCriteria.new | |
end | |
end | |
class UserCriteria | |
def id | |
LuckyRecord::AdvancedCriteria.new(:id) # can use ==, !=, >, <, >=, <=, .. (range) | |
end | |
def rating | |
LuckyRecord::IntegerCriter.new(:rating) # AdvancedCriteria plus avg, count, min, max | |
end | |
def name | |
LuckyRecord::StringCriteria.new(:name) # can use ==, !=, lower, length (returns an advanced criteria! | |
end | |
def created_at | |
LuckyRecord::DateTimeCriteria.new(:created_at) # Maybe same as AdvancedCriteria, but allows, date_parts and stuff like that | |
end | |
end | |
class LuckyRecord::TimeCriteria | |
#where(&.created.before 3.days.ago) | |
def before | |
end | |
def after | |
end | |
def at_or_before | |
end | |
def at_or_after | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://blog.heroku.com/solving-n-plus-one-queries