(no title)
jherdman | 1 year ago
class Account < ApplicationRecord
scope :active, -> { where.not(active_at: nil) }
belongs_to :user
end
class User < ApplicationRecord
scope :born_before, ->(born_on) { where(birthdate: born_on) }
end
active_users_with_birthdays_today = Account.active.joins(:user).merge(User.born_before(Date.today))
Contrived, of course, but it's not hard to see how you can use these sorts of things to build up record sorting, filtering, etc. Doing this by hand wouldn't be very fun.
sgarland|1 year ago
iterateoften|1 year ago
How are you canonically storing these predicates in code to reuse over 5-10 queries?
Eikon|1 year ago
iterateoften|1 year ago
Especially if you are defining types anyways to extract the data from the sql into.
unknown|1 year ago
[deleted]