Created
November 22, 2019 00:05
-
-
Save joegaudet/14fb9301b075f177fbac98e402fbd126 to your computer and use it in GitHub Desktop.
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
| # == Schema Information | |
| # | |
| # Table name: restaurants_menu_item_rankings | |
| # | |
| # id :integer | |
| # menu_id :integer | |
| # menu_item_name :string | |
| # count :decimal(, ) | |
| # | |
| class Restaurants::MenuItemRanking < ApplicationRecord | |
| attribute :total, :integer | |
| attribute :rank, :integer | |
| attribute :percent_tank, :float | |
| belongs_to :menu | |
| def self.refresh | |
| Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false) | |
| end | |
| def self.default_scope | |
| self.select( | |
| 'restaurants_menu_item_rankings.*', | |
| 'sum(count) over () as total', | |
| 'rank() over (order by count desc) as rank', | |
| 'percent_rank() over (order by count desc) as percent_rank' | |
| ) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment