What is the Expense Object Model?
The Expense
model represents individual financial expenses in the Finance Tracker application. It includes attributes such as name
, amount
, category
, and date
, allowing users to track and categorize their spending effectively.
Database Fields
The Expense
model includes the following fields, as defined in the database migration:
name
:
null: false
).amount
:
9999999999.99
is the largest number possible with this precision.12345.67
or 0.99
are valid with this scale.9999999999.99
), and a scale of 2 ensures accurate representation of cents or fractional currency units without rounding errors.null: false
), greater than 0.category
:
null: true
).date
:
null: false
).created_at
, updated_at
(automatically added by Rails).Model Validations
The Expense
model includes the following validations to ensure data integrity:
class Expense < ApplicationRecord
validates :name, presence: true
validates :amount, presence: true, numericality: { greater_than: 0 }
validates :date, presence: true
end
name
, amount
, and date
are present.amount
is greater than 0.