Last active
February 17, 2016 04:30
-
-
Save mrgenixus/aa33d28f445e80c55091 to your computer and use it in GitHub Desktop.
Extracted from ShoppingList#list_items as refactor
This file contains hidden or 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 :without_removed, -> { where(arel_table[:removed].eq(nil).or(arel_table[:removed].eq(0))) } | |
| scope :only_removed, -> { where(arel_table[:removed].not_eq(nil)).where(arel_table[:removed].not_eq(0)) } | |
| def self.date_range start_date, end_date | |
| includes(:event). | |
| where(Event.arel_table[:event].gteq(start_date)). | |
| where(Event.arel_table[:event].lteq(end_date)) | |
| end |
This file contains hidden or 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
| list_items = ShoppingListItems.where(user_id: current_user.id).include(:ingredients) | |
| list_items = list_items.date_range(start_date, end_date) | |
| list_items = list_items.without_removed if options[:hide_removed] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment