feat: 添加预算管理功能,包括其handler、service和repository层。
This commit is contained in:
@@ -66,8 +66,19 @@ func (r *BudgetRepository) Update(budget *models.Budget) error {
|
||||
return fmt.Errorf("failed to check budget existence: %w", err)
|
||||
}
|
||||
|
||||
// Update the budget
|
||||
if err := r.db.Save(budget).Error; err != nil {
|
||||
// Update the budget using Select to explicitly specify fields to update
|
||||
// This ensures that nil/NULL values for CategoryID and AccountID are properly saved
|
||||
if err := r.db.Model(budget).Select(
|
||||
"name",
|
||||
"amount",
|
||||
"period_type",
|
||||
"category_id", // Explicitly include to allow setting to NULL
|
||||
"account_id", // Explicitly include to allow setting to NULL
|
||||
"is_rolling",
|
||||
"start_date",
|
||||
"end_date",
|
||||
"updated_at",
|
||||
).Updates(budget).Error; err != nil {
|
||||
return fmt.Errorf("failed to update budget: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user