Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Adds rank to categories so you can set sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
inoda committed Aug 22, 2021
1 parent a161939 commit 7ca529a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ class Category < ApplicationRecord
validates_presence_of :name, :color

has_many :expenses

default_scope { order(rank: :asc, id: :asc) }
end
5 changes: 5 additions & 0 deletions db/migrate/20210822212320_adds_order_to_categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddsOrderToCategories < ActiveRecord::Migration[6.1]
def change
add_column :categories, :rank, :integer, default: 0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_10_05_195440) do
ActiveRecord::Schema.define(version: 2021_08_22_212320) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -21,6 +21,7 @@
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "monthly_goal", default: 0
t.integer "rank", default: 0
end

create_table "expenses", force: :cascade do |t|
Expand Down

0 comments on commit 7ca529a

Please sign in to comment.