$alumnos_internos = $this->getObject()->getgetAlumnoInternos();
$alumno_interno = $alumnos_internos[0];

Debes hacer eso porque en schema.yml no definiste la relación como uno
a uno
basta que con sólo definas:

type: one
foreignType: one
y cambia el foreignAlias a AlumnoInterno

en las relaciones asociadas y vuelvas a generar doctrine.
con eso solamente tendrás que hacer esto:

$alumnos_interno = $this->getObject()->getAlumnoInterno();
$alumno_interno_form = new AlumnoInternoForm($alumno_interno);
$this->embedForm('alumno_interno',$alumno_interno_form);

ahora esas 3 lineas están resumidas en el método embedRelation()

$this->embedRelation('AlumnoInterno');

donde AlumnoInterno es el nombre del foreignAlias

espero que esto te ayude a refactorizar tu codigo y que quede mas
depurado.
este ejempo esta hecho con Doctrine. en propel hay un plugin para usar
embedRelation pero
por lo que he leido no funciona muy bien


On 10 sep, 15:51, Alejandro Gómez <alejandro.go...@alejandrogomez.org>
wrote:
> I don't know why but embedRelation('AlumnoInterno') did not work.
> Maybe the Propel version?
>
> Symfony throws me "Call to undefined method
> AlumnoForm::embedRelation."
>
> In the other hand, I used getAlumnoInternos() wich "Gets an array of
> AlumnoInterno objects which contain a foreign key that references this
> object.". Since every Alumno object has only one AlumnoInterno object
> I take the first element of getAlumnoInternos().
>
> The code is as follows:
>
> [code]
> public function configure() {
>         parent::configure();
>
>         /*code portion removed*/
>
>         $alumnos_internos = $this->getObject()-
>
> >getgetAlumnoInternos();
>
>         $alumno_interno = $alumnos_internos[0];
>
>         $alumno_interno_form = new AlumnoInternoForm($alumno_interno);
>
>         $this->embedForm('alumno_interno', $alumno_interno_form);
>
>         /*code portion removed*/}
>
> [/code]
>
> Well, It works. However I am not sure if It is the best approach, do
> you?
>
> Thank you.
>
> On Sep 10, 12:03 pm, jota <jdeveloper.inxe...@gmail.com> wrote:
>
> > Try this:
>
> > public function configure() {
> >                parent::configure();
>
> >                /*code portion removed*/
>
> >                $alumno_interno = $this->getObject()->AlumnoInterno(); //if
> > the object Alumno is new it gives you an empty AlumnoInterno object, else it
> > gives you the associated AlumnoInterno
>
> >                $alumno_interno_form = new
> > AlumnoInternoForm($alumno_interno);
>
> >                $this->embedForm('alumno_interno',
> > $alumno_interno_form);
>
> >                /*code portion removed*/
> >        }
>
> > another way is to use embedRelation('AlumnoInterno') so you don't have to
> > deal with the save and getting the relation object to construct the subform
>
> > Hope it works
>
> > saludos
>
> > 2010/9/10 Alejandro Gómez <alejandro.go...@alejandrogomez.org>
>
> > > Hi folks.
>
> > > The database has two tables: 'alumno' and 'alumno_interno'. The
> > > 'alumno' table contains general data about students: name, lastname,
> > > address, etc. The 'alumno_interno' table contains details about the
> > > student: grade, control number, etc.
>
> > > The relationship between tables is:
>
> > > alumno {id, /*more fields*/}
> > > alumno_interno {id, id_alumno, /*more fields*/}
>
> > > On Symfony I built the models and forms. In fact, AlumnoInternoForm is
> > > already embedded on AlumnoForm.
>
> > > [code]
>
> > > /* AlumnoForm.class.php */
>
> > >        public function configure() {
> > >                parent::configure();
>
> > >                /*code portion removed*/
>
> > >                $alumno_interno = new AlumnoInterno;
> > >                $alumno_interno->setAlumno($this->getObject());
>
> > >                $alumno_interno_form = new
> > > AlumnoInternoForm($alumno_interno);
>
> > >                $this->embedForm('alumno_interno',
> > > $alumno_interno_form);
>
> > >                /*code portion removed*/
> > >        }
>
> > > [/code]
>
> > > I'm able to save a new student and his or her details in 'alumno' and
> > > 'alumno_interno' respectively.
>
> > > The trouble is when I try to edit an 'alumno' object: the AlumnoForm
> > > renders well and shows the embedded form (AlumnoInternoForm). The
> > > student's data is retrieved from the 'alumno' table but not from the
> > > 'alumno_interno' table. So, the AlumnoForm is well populated but the
> > > AlumnoInteroForm isn't. It's populated with the defaults values.
>
> > > I think I need to override a AlumnoForm method, maybe
> > > updateDefaultsFromObject(). Well, I did. But It didn't work. :-(
>
> > > Basically, I need to retrieve the AlumnoInterno object related to the
> > > Alumno object from the main form -AlumnoForm-, put the AlumnoInterno
> > > object inside the AlumnoInternoForm and update the AlumnoInternoForm's
> > > values in order to show the data. :-D
>
> > > How to do that? Someone?
>
> > > Software:
> > >        Symfony: 1.4.6
> > >        PHP: 5.3.2
>
> > > Thank you.
>
> > > --
> > > If you want to report a vulnerability issue on symfony, please send it to
> > > security at symfony-project.com
>
> > > You received this message because you are subscribed to the Google
> > > Groups "symfony users" group.
> > > To post to this group, send email to symfony-users@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > symfony-users+unsubscr...@googlegroups.com<symfony-users%2bunsubscr...@googlegroups.com>
> > > For more options, visit this group at
> > >http://groups.google.com/group/symfony-users?hl=en

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to