Created
November 15, 2019 08:42
-
-
Save sesharim/d751d83860dd977b64d89441009b7922 to your computer and use it in GitHub Desktop.
Arel
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
``` | |
scope :arel, ->(column, predication, *args) { where(arel_table[column].public_send(predication, *args)) } | |
``` | |
Example usage of the scope: | |
``` | |
MyModel.arel(:created_at, :lt, 2.days.ago) | |
``` | |
For all predications, check the documentation or source code. | |
This scope doesn't break the where chain. This means you can also do: | |
``` | |
MyModel.custom_scope1.arel(:created_at, :lt, 2.days.ago).arel(:updated_at, :gt, 2.days.ago).custom_scope2 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment