title: Symfony 2 - Multiple entities with one form
body: <p>I've got the following tables with relationships:</p>
  
  <ul>
  <li><code>UserAddress</code> table (Holds basic information for the address)</li>
  <li><code>UserAddressFields</code> table (Holds the value for each field associated to an address)</li>
  <li><code>UserAddressFieldsTranslation</code> table (Holds the field ids)</li>
  <li><code>UserStates</code> table (Holds the values of all the states in the US and the abbreviations)</li>
  </ul>
  
  <p>UserAddress has 2 foreign keys: </p>
  
  <ul>
  <li><code>Profile_id</code> -> <code>useraccounts.id</code></li>
  <li><code>state_id</code> -> <code>userstates.id</code></li>
  </ul>
  
  <p>UserAddressFields has one foreign key: </p>
  
  <ul>
  <li><code>address_id</code> -> <code>useraddress.id</code></li>
  </ul>
  
  <p>I've created entities for all 4 of these tables (Getters and Setters have been removed to save space, generated via console):</p>
  
  <p>UserAddress.php</p>
  
  <pre><code>&lt;?php
  namespace SCWDesignsBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use SCWDesignsBundle\Entity\UserStates;
  use UsersBundle\Entity\User;
  
  /**
   * @ORM\Entity(repositoryClass="SCWDesignsBundle\Entity\Repository\
  UserAddressesRepository")
   * @ORM\Table(name="user_addresses")
   */
  class UserAddresses {
      /**
       * @ORM\ID
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="UsersBundle\Entity\User")
       * @ORM\JoinColumn(name="profile_id", referencedColumnName="id")
       */
      protected $profile_id;
  
      /**
       * @ORM\ManyToOne(targetEntity="UserStates")
       * @ORM\JoinColumn(name="state_id", referencedColumnName="id")
       */
      protected $state_id;
  
      /**
       * @ORM\Column(type="boolean")
       */
      protected $isBilling;
  
      /**
       * @ORM\Column(type="boolean")
       */
      protected $isShipping;
  
      /**
       * @ORM\Column(type="string", columnDefinition="CHAR(1)")
       */
      protected $addressType;
  </code></pre>
  
  <p>UserAddressFieldsTranslation.php</p>
  
  <pre><code>&lt;?php
  namespace SCWDesignsBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use SCWDesignsBundle\Entity\UserAddressFields;
  use UsersBundle\Entity\User;
  
  /**
   * @ORM\Entity(repositoryClass="SCWDesignsBundle\Entity\Repository\UserAddressFieldsTranslationRepository")
   * @ORM\Table(name="user_address_fields_translation")
   */
  class UserAddressFieldsTranslation {
      /**
       * @ORM\ID
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\Column(type="string", columnDefinition="VARCHAR(255) NOT NULL")
       */
      protected $name;
  </code></pre>
  
  <p>UserStates.php</p>
  
  <pre><code>&lt;?php
  namespace SCWDesignsBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass="SCWDesignsBundle\Entity\Repository\StatesRepository")
   * @ORM\Table(name="user_states")
   */
  class UserStates {
      /**
       * @ORM\ID
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\Column(type="string", columnDefinition="CHAR(2)")
       */
      protected $country_code;
  
      /**
       * @ORM\Column(type="string", columnDefinition="VARCHAR(64)")
       */
      protected $state;
  </code></pre>
  
  <p>I have 2 form types, UserAddressFormType and UserAddressFieldsFormType.</p>
  
  <p>UserAddressFormType</p>
  
  <pre><code>&lt;?php
  namespace SCWDesignsBundle\Form\Type;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  
  class UserAddressFormType extends AbstractType {
      public function buildForm(FormBuilderInterface $builder, array $options) {
          $builder
              -&gt;add('profile_id', null, array('label' =&gt; 'Profile ID'))
              -&gt;add('state_id', null, array('label' =&gt; 'State ID'))
              -&gt;add('isBilling', null, array('label' =&gt; 'Billing Address'))
              -&gt;add('isShipping', null, array('label' =&gt; 'Shipping Address'))
              -&gt;add('addressType', null, array('label' =&gt; 'Address Type'))
              -&gt;add('addressFields', new UserAddressFieldsFormType());
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver) {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'SCWDesignsBundle\Entity\UserAddresses'
          ));
      }
  
      public function getName() {
          return 'UserAddressFormType';
      }
  }
  </code></pre>
  
  <p>UserAddressFieldsFormType.php</p>
  
  <pre><code>&lt;?php
  namespace SCWDesignsBundle\Form\Type;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  
  class UserAddressFieldsFormType extends AbstractType {
      public function buildForm(FormBuilderInterface $builder, array $options) {
          $builder
              -&gt;add('address_id', null, array('label' =&gt; 'Address Field'))
              -&gt;add('address_field_id', null, array('label' =&gt; 'Address Field ID'))
              -&gt;add('value', null, array('label' =&gt; 'Value'));
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver) {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'SCWDesignsBundle\Entity\UserAddressFields'
          ));
      }
  
      public function getName() {
          return 'UserAddressFieldsFormType';
      }
  }
  </code></pre>
  
  <p>In the controller is your basic form call.
  ProfileController.php</p>
  
  <pre><code>&lt;?php
  namespace SCWDesignsBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Response;
  use SCWDesignsBundle\Entity\UserAddresses;
  use SCWDesignsBundle\Form\Type\UserAddressFormType;
  use SCWDesignsBundle\Form\Type\UserAddressFieldsFormType;
  
  class ProfileController extends Controller {
      public function editAddressAction() {
          $address = new UserAddresses();
          $form_address = $this-&gt;createForm(new UserAddressFormType(), $address);
  
  
          $request = $this-&gt;getRequest();
          if ($request-&gt;getMethod() == 'POST') {
              // Perform some action.
  
              return $this-&gt;redirect($this-&gt;generateUrl('fos_user_profile_show'));
          }
  
  
  
          return $this-&gt;render('SCWDesignsBundle:Profile:edit.html.twig', array(
              'active_page' =&gt; 'profile',
              'form_address' =&gt; $form_address-&gt;createView(),
          ));
      }
  }
  </code></pre>
  
  <p>Everywhere I've read this is the correct means of adding another entity to your form builder but everytime I do this, or any other variation I've ran across I get the following error</p>
  
  <pre><code>Neither the property "addressFields" nor one of the methods
  "getAddressFields()", "isAddressFields()", "hasAddressFields()", "__get()" exist
  and have public access in class "SCWDesignsBundle\Entity\UserAddresses".
  </code></pre>