Skip to content

Instantly share code, notes, and snippets.

@sesharim
Created November 15, 2019 08:42
Show Gist options
  • Save sesharim/d751d83860dd977b64d89441009b7922 to your computer and use it in GitHub Desktop.
Save sesharim/d751d83860dd977b64d89441009b7922 to your computer and use it in GitHub Desktop.
Arel
```
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