Hi Tainder,
Well that depends if you want to modify the model itself or leave the model intact and modify the query
to understand what the model is doing as you customize your model just echo the query at the end of the prepareQuery function
But first
Although it may look like all of the models are loaded the switch statement takes care of which model / fields / filters etc are actually included in the query
switch($this->getState('context', 'all'))
{
case 'layoutname.modelname':
//BASE FIELDS
$this->addSelect( 'a.somefield,'
.......
.......
// $this->getState('context', 'all') returns the the layout names and associated model
// $this->getState('context', 'all') would be in the following format layoutname.modelname
// and the case picks up the layout and model name
// so you can set the state in your display function located in the specific view.html.php file
$state->set('context', 'layoutname.modelname');
to call the model from somewhere in your code
$model = Model::getInstance('component', 'viewModel');
// add field to the query in the model
$this->addSelect('a.somefield AS field');
to modify the model you can add various options
$model = Model::getInstance('component', 'viewModel');
// add field to the current model somewhere in your code
model->addSelect('a.somefield AS field');
// call a specific instance of the model
// somewhere in your code
$model = Model::getInstance('component', 'viewModel');
// call a second model
$modelTwo = Model::getInstance('component', 'viewModelTwo');
Left Join in the model (example)
//SELECT
$this->addSelect('_left_table_alias_.field AS `_left_table_alias_some_field`');
//JOIN
$this->addJoin('`#__left_table_name` AS _left_tabl_alias_ ON _left_table_alias_.id = a.some_some_field', 'LEFT');
Adding to the $query variable in the model
you can call some custom function to build a custom query parameter such as below and simply add it to the $query variable
$join = buildMyLeftJoin();
// and this function would then return something like
// '`#__left_table_name` AS _left_tabl_alias_ ON _left_tabl_alias_.id = a.some_some_field';
$query->join('LEFT', $join);
adding Where
$query->where('a.id = somevalue');
$this->addWhere('a.id = somevalue');
// somewhere in your code, view, helper...
$model->addWhere('a.id = somevalue');
so here would be a practical example...
so lets say you want to completely replace the model that is normally used in that layout and your replacement model has no joins no filters but you want some data from another table and filter the data
// get the alternate model
$model = $model = Model::getInstance('component', 'viewModel');
//-- create the left join --//
// add the select
$model->addSelect('_some_table_alias.some_field AS some_table_alias_some_field')
// add the left join
$model->$this->addJoin('`#__some_table` AS _some_table_alias_ ON _some_table_alias_.id = a.some_some_field', 'LEFT');
// apply a filter to the query
$model->addWhere('a.id = _some_table_alias_some_field');
So now you have a completely different filtered, left joined dataset available in your layout
PS Its late here... if i have made a mistake in my explanation i apologize in advance and only too happy to adjust this reply should there be a mistake
but hope it helps to understand a little better