Here the solution I encountered: I've separated the problem in two.
Case 1: New Record
I use the same JQuery function shown above in the question. With the associated function, also shown above. This case was not part of my problem
Case 2: Edit an existing record (here was my problem)
I added for 'id_subsector_actividad'
in the widget the property 'table_method'=>'Subsector'
associated with the function public function Subsector()
(see below code).
In the partial _form.php of conflictos1, I wrote the following code for the field id_subsector_actividad
:
<?php if (!$form->getObject()->isNew()): ?>
<?php echo $form['id_subsector_actividad'] ?>
<?php endif; ?>
<?php if ($form->getObject()->isNew()): ?>
<select name="conflictos1[id_subsector_actividad]" id="conflictos1_id_subsector_actividad">
<option value="" selected="selected">Seleccione sub-sector</option>
<?php endif; ?>
In the action.class.php in the conflictos1, I modified the function executeEdit, with the addition of the variable $elsector
:
public function executeEdit(sfWebRequest $request)
{
global $elsector;
$this->forward404Unless($conflictos1 = Doctrine_Core::getTable('Conflictos1')->find(array($request->getParameter('id'))), sprintf('Object conflictos1 does not exist (%s).', $request->getParameter('id')));
$elsector= $conflictos1->getIdSectorActividad();
$this->form = new Conflictos1Form($conflictos1);
}
I use $elsector
in the following function created in SubsectorActividadTa8Table.class.php
public function Subsector()
{
global $elsector;
if (!is_null($elsector)){
$id_sub=$elsector;
$query= Doctrine_Query::create()
->select('a.id')
->from('SubsectorActividadTa8 a')
->innerJoin('a.Conflictos1 c')
->where('a.id_sector = ?', $id_sub);
return $query->execute();
}
}
Thus, Symfony displayed on the form, the value of field named IdSubsectorActividad, not previously exhibited.
In other words, now when I'm editing a record in the table conflictos1
the field named IdSubsectorActividad shows the correct value, whereas before the form does not show any value.
Now everything works fine!.