One minute
Use invert_where to invert where clause ๐งฉ
With Rails 7.0, you can use invert_where to invert an entire where clause instead of manually applying conditions ๐ฃ
Code snippet ๐
# Version: Rails 7.0
class User
scope :active, -> { where(is_active: true) }
end
# Before
active_users = User.active
inactive_users = User.where(active: false)
# After
active_users = User.active
inactive_users = User.active.invert_where
Read other posts
comments powered by Disqus