Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CategoriesController < ApplicationController
before_action :set_transaction, only: :create

def index
@categories = Current.family.categories.alphabetically.to_a
@categories = Current.family.categories.alphabetically_by_hierarchy.to_a
@category_groups = Category::Group.for(@categories)
@category_ids_with_transactions = category_ids_with_transactions(@categories)

Expand Down
6 changes: 5 additions & 1 deletion app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ class Category < ApplicationRecord
belongs_to :family

has_many :budget_categories, dependent: :destroy
has_many :subcategories, class_name: "Category", foreign_key: :parent_id, dependent: :nullify
has_many :subcategories,
-> { order(:name) },
class_name: "Category",
foreign_key: :parent_id,
dependent: :nullify
belongs_to :parent, class_name: "Category", optional: true

validates :name, :color, :lucide_icon, :family, presence: true
Expand Down
Loading