Well,
You cannot implement it in your SQL query. You must have another call.
The only way to do it in one query, is to create a groupby on a food budget list. but is is limited to these page only, so it is a wrong way if you want to be free.
I think for you, below is the correct answer :
(It works on an ITEM model for the moment)
in your model, models/budget.php :
1. Create a new function : (copy / paste this)
public function populateObjects(&$item)
{
$modelFoodbudgets = JModel::getInstance('Foodbudgets', 'BudgetsModel');
$modelFoodbudgets->addWhere('a.budget = ' . (int)$item->id);
$item->foodbudget = $modelFoodbudgets->getItems();
}
2.Test it
3 lines. That's it !
Note : The amazing stuff is that populateObject function is available in infinite cascads !
I mean if you add such code in your foodbudgets model to obtain another N:1 links, you will get them also from budgets model.
It is really easy.
So, please consider also if you always need theses items everytime you load a budget.
This solution I propose you will ALWAYS load the foodbudgets items, even when you open a page that do not need it.
If you want to restrict the loading of the N:1 items, use the states vars :
In our example, let's define a state namespace : 'objects.budgets'
public function populateObjects(&$item)
{
if ($this->getState('objects.budgets')) //Custom namespace here
{
$modelFoodbudgets = JModel::getInstance('Foodbudgets', 'BudgetsModel');
$modelFoodbudgets->addWhere('a.budget = ' . (int)$item->id);
$item->foodbudget = $modelFoodbudgets->getItems();
}
}
And this in your view file BEFORE to load the items :
$state->set('objects.budgets', true); //ADD THIS
$this->item = $item = $this->get('Item'); //loads the Items, do not touch