basic-scopes
ActiveRecord basic scopes.
Usage
You can use basic-scopes just as normal ActiveRecord methods.
Filtering
except_id(id)
- all records without matchingID
fieldfilter_id(id)
- all records with matchingID
fieldexcept_ids(ids)
- all records without matchingID
fieldfilter_ids(ids)
- all records with matchingID
fieldfilter_updated_since(time)
- all records that haveUPDATED_AT
field greater thantime
filter_updated_till(time)
- all records that haveUPDATED_AT
field lesser thantime
filter_created_since(time)
- all records that haveCREATED_AT
field greater thantime
filter_created_till(time)
- all records that haveCREATED_AT
field lesser thantime
NOTE: ids
param is an Array of ID
s; id
is single value
Sorting / OrderBy
by_id
- order byID
descendingby_id_reversed
- order byID
ascendingby_created_at
- order byCREATED_AT
descendingby_created_at_reversed
- order byCREATED_AT
ascendingby_updated_at
- order byUPDATED_AT
descendingby_updated_at_reversed
- order byUPDATED_AT
ascending
Examples
Account.except_id(1)
- All Accounts except ID == 1.
User.filter_updated_since(1.day).by_updated_at
- All Users updated in the last one day, ordered by time