Hi Levi
Have set up a test component
Companies (collection) / Company (item)
[company_name]
[company_address]
Departments (collection) / Department (item)
[department_name]
[department_leader]
[company_id]
In Your Company Item Controller you need to pass the company_name as shown below see comment.
Offered as a work around but as always open to options if anyone else has alternate / cleaner solution
Hope it helps get you on the right track...
switch($this->getLayout() .'.'. $this->getTask())
{
case 'makecompany.save':
$this->applyRedirection($result, array(
'com_company.company.makecompany',
'com_company.department.department'
), array(
'cid[]' => null,
'filter_company_id' => $model->getState('company.id'),
// <= added comma in the line above
// <= added the line below to get the value of company_name from the model
'_company_id_company_name' => $model->getItem()->company_name
));
break;
}
And In your Department Model - the value of company name is not populated until the department view is saved (save and close button) or applied (save button). Need to add the company name to the default values - see note in code below
The default values are set here in your department model
// Prime some default values.
if ($this->getState('department.id') == 0)
{
$jinput = new JInput;
$data->id = 0;
$data->params = null;
$data->department_name = null;
$data->department_leader = null;
$data->company_id = $jinput->get('filter_company_id', $this->getState('filter.company_id'), 'INT');
// Added the following line to pre-populate the company name
$data->_company_id_company_name = $jinput->get('_company_id_company_name');
}
Further down in your model you will find the name of the field you need - see comment in code below
switch($this->getState('context'))
{
case 'department.department':
//BASE FIELDS
$this->addSelect( 'a.company_id,'
. 'a.department_name,'
. 'a.department_leader');
//SELECT
// the field name to pre populate in the default values is found here
// NOTE: the underscore!
$this->addSelect('_company_id_.company_name AS `_company_id_company_name`');
//JOIN
$this->addJoin('`#__company_companies` AS _company_id_ ON _company_id_.id = a.company_id', 'LEFT');
break;