title: Symfony 2 Embedded forms using one to many db relationship
body: <p>I'm have a problem embedding forms from different entities in one form, my form is being displayed with firstname [input] lastname [input] address - but the address has no input next to it.</p>
  
  <p>Basically I want to create a form where the user can add first name, last name, address1, address2, city, country ect and submit it it as one, although it's different tables.</p>
  
  <p>The main form is no problem the only issue I'm having is with the second embedded form. Any help would be greatly appreciated.</p>
  
  <p>Here is my code: </p>
  
  <p>Member class:</p>
  
  <pre><code>namespace Pomc\MembersBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * Pomc\MembersBundle\Entity\Member
  */
  class Member
  {
  /**
   * @var integer $id
   */
  private $id;
  
  /**
   * @var string $firstName
   */
  private $firstName;
  
  /**
   * @var string $lastName
   */
  private $lastName;
  
  /**
   * @var Pomc\MembersBundle\Entity\Address
   */
  private $address;
  
  /**
   * @var Pomc\MembersBundle\Entity\Telephone
   */
  private $telephone;
  
  public function __construct()
  {
      $this-&gt;address = new \Doctrine\Common\Collections\ArrayCollection();
      $this-&gt;telephone = new \Doctrine\Common\Collections\ArrayCollection();
  }
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set firstName
   *
   * @param string $firstName
   */
  public function setFirstName($firstName)
  {
      $this-&gt;firstName = $firstName;
  }
  
  /**
   * Get firstName
   *
   * @return string 
   */
  public function getFirstName()
  {
      return $this-&gt;firstName;
  }
  
  /**
   * Set lastName
   *
   * @param string $lastName
   */
  public function setLastName($lastName)
  {
      $this-&gt;lastName = $lastName;
  }
  
  /**
   * Get lastName
   *
   * @return string 
   */
  public function getLastName()
  {
      return $this-&gt;lastName;
  }
  
  /**
   * Add address
   *
   * @param Pomc\MembersBundle\Entity\Address $address
   */
  public function addAddress(\Pomc\MembersBundle\Entity\Address $address)
  {
      $this-&gt;address[] = $address;
  }
  
  /**
   * Get address
   *
   * @return Doctrine\Common\Collections\Collection 
   */
  public function getAddress()
  {
      return $this-&gt;address;
  }
  
  /**
   * Add telephone
   *
   * @param Pomc\MembersBundle\Entity\Telephone $telephone
   */
  public function addTelephone(\Pomc\MembersBundle\Entity\Telephone $telephone)
  {
      $this-&gt;telephone[] = $telephone;
  }
  
  /**
   * Get telephone
   *
   * @return Doctrine\Common\Collections\Collection 
   */
  public function getTelephone()
  {
      return $this-&gt;telephone;
  }
  }
  </code></pre>
  
  <p>Here is the address class:</p>
  
  <p>
  
  <pre><code>namespace Pomc\MembersBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Pomc\MembersBundle\Entity\Address
   */
  class Address
  {
      /**
       * @var integer $id
       */
      private $id;
  
      /**
       * @var string $addressType
       */
      private $addressType;
  
      /**
       * @var string $firstLine
       */
      private $firstLine;
  
      /**
       * @var string $secondLine
       */
      private $secondLine;
  
      /**
       * @var string $city
       */
      private $city;
  
      /**
       * @var string $postCode
       */
      private $postCode;
  
      /**
       * @var string $country
       */
      private $country;
  
      /**
       * @var Pomc\MembersBundle\Entity\Member
       */
      private $member;
  
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set addressType
       *
       * @param string $addressType
       */
      public function setAddressType($addressType)
      {
          $this-&gt;addressType = $addressType;
      }
  
      /**
       * Get addressType
       *
       * @return string 
       */
      public function getAddressType()
      {
          return $this-&gt;addressType;
      }
  
      /**
       * Set firstLine
       *
       * @param string $firstLine
       */
      public function setFirstLine($firstLine)
      {
          $this-&gt;firstLine = $firstLine;
      }
  
      /**
       * Get firstLine
       *
       * @return string 
       */
      public function getFirstLine()
      {
          return $this-&gt;firstLine;
      }
  
      /**
       * Set secondLine
       *
       * @param string $secondLine
       */
      public function setSecondLine($secondLine)
      {
          $this-&gt;secondLine = $secondLine;
      }
  
      /**
       * Get secondLine
       *
       * @return string 
       */
      public function getSecondLine()
      {
          return $this-&gt;secondLine;
      }
  
      /**
       * Set city
       *
       * @param string $city
       */
      public function setCity($city)
      {
          $this-&gt;city = $city;
      }
  
      /**
       * Get city
       *
       * @return string 
       */
      public function getCity()
      {
          return $this-&gt;city;
      }
  
      /**
       * Set postCode
       *
       * @param string $postCode
       */
      public function setPostCode($postCode)
      {
          $this-&gt;postCode = $postCode;
      }
  
      /**
       * Get postCode
       *
       * @return string 
       */
      public function getPostCode()
      {
          return $this-&gt;postCode;
      }
  
      /**
       * Set country
       *
       * @param string $country
       */
      public function setCountry($country)
      {
          $this-&gt;country = $country;
      }
  
      /**
       * Get country
       *
       * @return string 
       */
      public function getCountry()
      {
          return $this-&gt;country;
      }
  
      /**
       * Set member
       *
       * @param Pomc\MembersBundle\Entity\Member $member
       */
      public function setMember(\Pomc\MembersBundle\Entity\Member $member)
      {
          $this-&gt;member = $member;
      }
  
      /**
       * Get member
       *
       * @return Pomc\MembersBundle\Entity\Member 
       */
      public function getMember()
      {
          return $this-&gt;member;
      }
  }
  </code></pre>
  
  <p>Here is the memberform:</p>
  
  <p>
  
  <pre><code>namespace Pomc\MembersBundle\Form\Type;
  
  use \Symfony\Component\Form\AbstractType;
  use \Symfony\Component\Form\FormBuilder;
  
  class MemberType extends AbstractType
  {
      public function buildForm(FormBuilder $builder, array $options)
      {
          $builder-&gt;add('firstName');
          $builder-&gt;add('lastName');
          $builder-&gt;add('address','collection', array( 'type' =&gt;  new AddressType(),
                                                'allow_add' =&gt; true,
                                                'prototype' =&gt; true,
                                                'by_reference' =&gt; false,
                                                ));
      }
  
      public function getDefaultOptions(array $options)
      {
          return array('data_class' =&gt; 'Pomc\MembersBundle\Entity\Member');
      }
      /**
       * Returns the name of this type.
       *
       * @return string The name of this type
       */
      function getName()
      {
          return 'member';
      }
  
  
  }
  </code></pre>
  
  <p>Here is the address form:</p>
  
  <p>
  
  <pre><code>namespace Pomc\MembersBundle\Form\Type;
  
  use \Symfony\Component\Form\AbstractType;
  use \Symfony\Component\Form\FormBuilder;
  
  
  class AddressType extends AbstractType
  {
      public function buildForm(Formbuilder $builder, array $options)
      {
          $builder-&gt;add('firstLine');
  
      }
  
      public function getDefaultOptions(array $options)
      {
          return array('data_class' =&gt; 'Pomc\MembersBundle\Entity\Address');
      }
      /**
       * Returns the name of this type.
       *
       * @return string The name of this type
       */
      function getName()
      {
          return 'address';
      }
  
      function getIdentifier()
      {
          return 'address';
      }
  }
  </code></pre>
  
  <p>Here is the controller:</p>
  
  <p>
  
  <pre><code>namespace Pomc\MembersBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use \Pomc\MembersBundle\Entity\Member;
  use \Symfony\Component\HttpFoundation\Request;
  use \Pomc\MembersBundle\Form\Type\MemberType;
  
  class DefaultController extends Controller
  {
  
      public function indexAction($name)
      {
          return $this-&gt;render('PomcMembersBundle:Default:index.html.twig', array('name' =&gt; $name));
      }
  
      public function newAction(Request $request)
      {
  
          $member = new Member();
  
          $form = $this-&gt;get('form.factory')-&gt;create(new MemberType());
  
          if($request-&gt;getMethod() == 'POST')
          {
              $form-&gt;bindRequest($request);
  
              if($form-&gt;isValid())
              {
                  $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
                  $em-&gt;persist($member);
                  $em-&gt;flush();
  
              }
          }
          return $this-&gt;render('PomcMembersBundle:Default:new.html.twig', array( 'form'=&gt; $form-&gt;createView(),));
  
      }
  }
  </code></pre>
  
  <p>Here is the template:</p>
  
  <pre><code>&lt;form action="{{ path('member_new') }}" method="post" {{ form_enctype(form)}}&gt;
      {{ form_widget(form) }}
      &lt;div&gt;
      {{ form_row(form.address)}}
      &lt;/div&gt;
      &lt;input type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Been a long time user of this site, but this is my first question.</p>
  
  <p>Thank you </p>