Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "embed"

auto save embedded form foreign key

public function saveEmbeddedForms($con = null, $forms = null)
  {
    if (is_null($con))
    {
      $con = $this->getConnection();
    }
 
    if (is_null($forms))
    {
      $forms = $this->embeddedForms;
    }
 
    foreach ($forms as $form)
    {
      if ($form instanceof sfFormDoctrine)
      {
        // The magic start here
        $field_name  = $this->getObject()->getTable()->getTableName().'_id';
        if($form->getObject()->contains($field_name)) {
          $method_name = 'set'.sfInflector::camelize($field_name);
          $form->getObject()->$method_name($this->getObject()->getId());
        }
        // Here it ends
        $form->getObject()->save($con);
        $form->saveEmbeddedForms($con);
      }
      else
      {
        $this->saveEmbeddedForms($con, $form->getEmbeddedForms());
      }
    }
 
by Marc Carlucci on 2009-09-01, tagged doctrine  embed  embedform 
(3 comments)