title: Add selectbox with values of relation in Symfony
body: <p>I'm a Symfony beginner and I'm eager to learn more about Symfony, that's why I started a learning project.</p>
  
  <p>I have a many-to-one relation (Type has many Games, but Game has 1 Type), and I would like to show a select box with a list of  "types" to choose from.</p>
  
  <p>I get this error:</p>
  
  <pre><code>Could not load type "AppBundle\Form\choiceType"
  </code></pre>
  
  <p>This is my code:</p>
  
  <p>GameController.php</p>
  
  <pre><code>&lt;?php
  namespace AppBundle\Controller;
  
  use AppBundle\Entity\Game;
  use AppBundle\Entity\Type;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;
  
  /**
   * Game controller.
   *
   * @Route("game")
   */
  class GameController extends Controller
  {
      /**
       * Lists all game entities.
       *
       * @Route("/", name="game_index")
       * @Method("GET")
       */
      public function indexAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $games = $em-&gt;getRepository('AppBundle:Game')-&gt;findAll();
  
          return $this-&gt;render('game/index.html.twig', array(
              'games' =&gt; $games,
          ));
      }
  
      /**
       * Creates a new game entity.
       *
       * @Route("/new", name="game_new")
       * @Method({"GET", "POST"})
       */
      public function newAction(Request $request)
      {
  
          $type = new Type();
          $type-&gt;setName('test');
  
          $game = new Game();
  
          $game-&gt;setType($type);
  
          $form = $this-&gt;createForm('AppBundle\Form\GameType', $game);
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;persist($type);
              $em-&gt;persist($game);
              $em-&gt;flush($game);
  
              return $this-&gt;redirectToRoute('game_show', array('id' =&gt; $game-&gt;getId()));
          }
  
          return $this-&gt;render('game/new.html.twig', array(
              'game' =&gt; $game,
              'form' =&gt; $form-&gt;createView(),
          ));
      }
  
      /**
       * Finds and displays a game entity.
       *
       * @Route("/{id}", name="game_show")
       * @Method("GET")
       */
      public function showAction(Game $game)
      {
          $deleteForm = $this-&gt;createDeleteForm($game);
  
          return $this-&gt;render('game/show.html.twig', array(
              'game' =&gt; $game,
              'delete_form' =&gt; $deleteForm-&gt;createView(),
          ));
      }
  
      /**
       * Displays a form to edit an existing game entity.
       *
       * @Route("/{id}/edit", name="game_edit")
       * @Method({"GET", "POST"})
       */
      public function editAction(Request $request, Game $game)
      {
          $deleteForm = $this-&gt;createDeleteForm($game);
          $editForm = $this-&gt;createForm('AppBundle\Form\GameType', $game);
          $editForm-&gt;handleRequest($request);
  
          if ($editForm-&gt;isSubmitted() &amp;&amp; $editForm-&gt;isValid()) {
              $this-&gt;getDoctrine()-&gt;getManager()-&gt;flush();
  
              return $this-&gt;redirectToRoute('game_edit', array('id' =&gt; $game-&gt;getId()));
          }
  
          return $this-&gt;render('game/edit.html.twig', array(
              'game' =&gt; $game,
              'edit_form' =&gt; $editForm-&gt;createView(),
              'delete_form' =&gt; $deleteForm-&gt;createView(),
          ));
      }
  
      /**
       * Deletes a game entity.
       *
       * @Route("/{id}", name="game_delete")
       * @Method("DELETE")
       */
      public function deleteAction(Request $request, Game $game)
      {
          $form = $this-&gt;createDeleteForm($game);
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;remove($game);
              $em-&gt;flush($game);
          }
  
          return $this-&gt;redirectToRoute('game_index');
      }
  
      /**
       * Creates a form to delete a game entity.
       *
       * @param Game $game The game entity
       *
       * @return \Symfony\Component\Form\Form The form
       */
      private function createDeleteForm(Game $game)
      {
          return $this-&gt;createFormBuilder()
              -&gt;setAction($this-&gt;generateUrl('game_delete', array('id' =&gt; $game-&gt;getId())))
              -&gt;setMethod('DELETE')
              -&gt;getForm()
          ;
      }
  }
  </code></pre>
  
  <p>Update #3:</p>
  
  <pre><code>GameType.php
  &lt;?php
  
  namespace AppBundle\Form;
  use Doctrine\DBAL\Types\TextType;
  use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  
  class GameType extends AbstractType
  {
      /**
       * {@inheritdoc}
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add( 'name', EntityType::class, [
                  'class' =&gt; 'AppBundle:Game',
                  'choice_label' =&gt; 'name',
                  'label' =&gt; 'name'
              ] );
          $builder
              -&gt;add( 'name', EntityType::class, [
                  'class' =&gt; 'AppBundle:Type',
                  'choice_label' =&gt; 'name',
                  'multiple' =&gt; false,
                  'expanded' =&gt; false
              ] );
  
  
      }
  
      /**
       * {@inheritdoc}
       */
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'AppBundle\Entity\Game'
          ));
      }
  
      /**
       * {@inheritdoc}
       */
      public function getBlockPrefix()
      {
          return 'appbundle_game';
      }
  
  
  }
  </code></pre>
  
  <p>Entity\Game.php</p>
  
  <pre><code>namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  
  
  /**
   * Game
   *
   * @ORM\Table(name="game")
   * @ORM\Entity(repositoryClass="AppBundle\Repository\GameRepository")
   */
  class Game
  {
      /**
       * @ORM\ManyToOne(targetEntity="Type", inversedBy="games")
       * @ORM\JoinColumn(name="type_id", referencedColumnName="id")
       */
      private $type;
  
  
  
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=255, unique=true)
       */
      private $name;
  
  
      /**
       * Get id
       *
       * @return int
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set name
       *
       * @param string $name
       *
       * @return Game
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  
      /**
       * @return mixed
       */
      public function getType()
      {
          return $this-&gt;type;
      }
  
      /**
       * @param mixed $type
       */
      public function setType($type)
      {
          $this-&gt;type = $type;
      }
  
  
  
  }
  </code></pre>
  
  <p>Entity\Type.php</p>
  
  <pre><code>namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  
  
  /**
   * Type
   *
   * @ORM\Table(name="type")
   * @ORM\Entity(repositoryClass="AppBundle\Repository\TypeRepository")
   */
  class Type
  {
      /**
       * @ORM\OneToMany(targetEntity="Game", mappedBy="type")
       */
      private $games;
  
      public function __construct()
      {
          $this-&gt;games = new ArrayCollection();
      }
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=255)
       */
      private $name;
  
  
  
  
      /**
       * Get id
       *
       * @return int
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set name
       *
       * @param string $name
       *
       * @return Type
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  
      /**
       * @return mixed
       */
      public function getGames()
      {
          return $this-&gt;games;
      }
  
      /**
       * @param mixed $games
       */
      public function setGames($games)
      {
          $this-&gt;games = $games;
      }
  
  }
  </code></pre>