title: Symfony2 Entity to array
body: <p>I'm trying to migrate my flat php project to Symfony2, but its coming to be very hard.
  For instance, I have a table of Products specification that have several specifications and are distinguishables by its "cat" attribute in that Extraspecs DB table.
  Therefore I've created a Entity for that table and want to make an array of just the specifications with "cat" = 0...</p>
  
  <p>I supose the code is this one.. right?</p>
  
  <pre><code>$typeavailable = $this-&gt;getDoctrine()
          -&gt;getRepository('LabsCatalogBundle:ProductExtraspecsSpecs')
          -&gt;findBy(array('cat' =&gt; '0'));
  </code></pre>
  
  <p>Now how can i put this in an array to work with a form like this?:</p>
  
  <pre><code>form = $this -&gt;createFormBuilder($product)
  -&gt;add('specs', 'choice', array('choices' =&gt; $typeavailableArray), 'multiple' =&gt; true)  
  </code></pre>
  
  <p>Thank you in advance :)</p>
  
  #
  
  <p>Thank you all..</p>
  
  <p>But now I've came across with another problem..
  In fact i'm building a form from an existing object:</p>
  
  <pre><code>$form = $this -&gt;createFormBuilder($product)
                  -&gt;add('name', 'text')
                  -&gt;add('genspec', 'choice', array('choices' =&gt; array('0' =&gt; 'None', '1' =&gt; 'General', '2' =&gt; 'Specific')))
                  -&gt;add('isReg', 'choice', array('choices' =&gt; array('0' =&gt; 'Material', '1' =&gt; 'Reagent', '2' =&gt; 'Antibody', '3' =&gt; 'Growth Factors', '4' =&gt; 'Rodents', '5' =&gt; 'Lagomorphs')))
  </code></pre>
  
  <p>So.. in that case my current value is named "extraspecs", so i've added this like:</p>
  
  <pre><code>-&gt;add('extraspecs', 'entity', array(
                          'label'          =&gt; 'desc',
                          'empty_value'    =&gt; ' --- ',
                          'class'          =&gt; 'LabsCatalogBundle:ProductExtraspecsSpecs',
                          'property'       =&gt; 'specsid',
                          'query_builder'  =&gt; function(EntityRepository $er) {
                              return $er -&gt;createQueryBuilder('e');
  </code></pre>
  
  <p>But "extraspecs" come from a relationship of oneToMany where every product has several extraspecs...</p>
  
  <p>Here is the ORM:</p>
  
  <pre><code>Labs\CatalogBundle\Entity\Product:
      type: entity
      table: orders__regmat
      id:
          id:
              type: integer
              generator: { strategy: AUTO }
      fields:
          name:
              type: string
              length: 100
          catnumber:
              type: string
              scale: 100
          brand:
              type: integer
              scale: 10
          company:
              type: integer
              scale: 10
          size:
              type: decimal
              scale: 10
          units:
              type: integer
              scale: 10
          price:
              type: decimal
              scale: 10
          reqcert:
              type: integer
              scale: 1
          isReg:
              type: integer
              scale: 1
          genspec:
              type: integer
              scale: 1
  
      oneToMany:
          extraspecs:
              targetEntity: ProductExtraspecs
              mappedBy: product
  
  Labs\CatalogBundle\Entity\ProductExtraspecs:
      type: entity
      table: orders__regmat__extraspecs
  
      fields:
          extraspecid:
              id: true
              type: integer
              unsigned: false
              nullable: false
              generator:
                  strategy: IDENTITY
          regmatid:
              type: integer
              scale: 11
          spec:
              type: integer
              scale: 11
          attrib:
              type: string
              length: 20
          value:
              type: string
              length: 200
  
      lifecycleCallbacks: {  }
  
  
      manyToOne:
        product:
          targetEntity: Product
          inversedBy: extraspecs
          joinColumn:
              name: regmatid
              referencedColumnName: id
  </code></pre>
  
  <p>HOw should I do this?</p>
  
  <p>Thank you!!!      </p>