A fix for a bug that would prevent both the category and the budget to be updated.

This commit is contained in:
James Cole 2014-11-20 07:12:41 +01:00
parent 114d3812cc
commit d3a7596be2

View File

@ -221,17 +221,15 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
} }
/* /*
* Store the budget. * Update the budget and the category.
*/ */
\Log::info('Before budget id.'); $components = [];
if (isset($data['budget_id']) && intval($data['budget_id']) > 0) { if (isset($data['budget_id']) && intval($data['budget_id']) > 0) {
/** @var \FireflyIII\Database\Budget $budgetRepository */ /** @var \FireflyIII\Database\Budget $budgetRepository */
$budgetRepository = \App::make('FireflyIII\Database\Budget'); $budgetRepository = \App::make('FireflyIII\Database\Budget');
$budget = $budgetRepository->find(intval($data['budget_id'])); $budget = $budgetRepository->find(intval($data['budget_id']));
\Log::info('Isset budget id!');
if ($budget) { if ($budget) {
\Log::info('Sync!'); $components[] = $budget->id;
$model->budgets()->sync([$budget->id]);
} }
} }
if (strlen($data['category']) > 0) { if (strlen($data['category']) > 0) {
@ -239,9 +237,10 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
$categoryRepository = \App::make('FireflyIII\Database\Category'); $categoryRepository = \App::make('FireflyIII\Database\Category');
$category = $categoryRepository->firstOrCreate($data['category']); $category = $categoryRepository->firstOrCreate($data['category']);
if ($category) { if ($category) {
$model->categories()->sync([$category->id]); $components[] = $category->id;
} }
} }
$model->components()->sync($components);
/* /*
* Now we can update the transactions related to this journal. * Now we can update the transactions related to this journal.