title: Create Doctrine associations
body: <p>I need to create 3 heaths with the appropriate names and fields, I know what the SQL query should look like, but I do not know how to do it in the doctrine. Tell me, please, how it can be implemented.</p>
  
  <pre><code>CREATE TABLE item (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(30) NOT NULL, PRIMARY KEY(id));
  CREATE TABLE attribute (id INT AUTO_INCREMENT NOT NULL, alias VARCHAR(30) NOT NULL, name VARCHAR(30) NOT NULL, PRIMARY KEY(id));
  CREATE TABLE attr_value (id INT AUTO_INCREMENT NOT NULL, item_id INT NOT NULL, attribute_id INT NOT NULL, value VARCHAR(30), PRIMARY KEY(id), FOREIGN KEY (item_id) REFERENCES item (id), FOREIGN KEY (attribute_id) REFERENCES attribute (id));
  </code></pre>
  
  <p>The bottom line is that you need to make a table where there will be a name of item, a table with the name of the attribute and a table that links them, and in which there are fields: item_id, attribute_id and the value of the attribute. I am hope for your help!</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>My Item Entity:</p>
  
  <pre><code>class Item
  {
      private $id;
      private $name;
      protected $itemValues;
      public function __construct()
      {
          $this-&gt;itemValues = new ArrayCollection();
      }
  //getters and setters
  }
  </code></pre>
  
  <p>Attribute Entity:</p>
  
  <pre><code>class Attribute
  {
      private $id;
      private $alias;
      private $name;
      protected $attrValues;
  //getters and setters
  }
  </code></pre>
  
  <p>AttrValue Entity:</p>
  
  <pre><code>class AttrValue
  {
      private $id;
      private $value;
      protected $attribute;
      protected $item;
  //getters and setters
  }
  </code></pre>
  
  <p>Item.orm.yml:</p>
  
  <pre><code>AppBundle\Entity\Item:
      type: entity
      oneToMany:
          itemValues:
              targetEntity: AppBundle\Entity\AttrValue
              mappedBy: item
      table: items
      repositoryClass: AppBundle\Repository\ItemRepository
      id:
          id:
              type: integer
              id: true
              generator:
                  strategy: AUTO
      fields:
          name:
              type: string
              length: 255
  </code></pre>
  
  <p>Attribute.orm.yml:</p>
  
  <pre><code>AppBundle\Entity\Attribute:
      type: entity
      oneToMany:
              attrValues:
                  targetEntity: AppBundle\Entity\AttrValue
                  mappedBy: attribute
      table: attribute
      repositoryClass: AppBundle\Repository\AttributeRepository
      id:
          id:
              type: integer
              id: true
              generator:
                  strategy: AUTO
      fields:
          alias:
              type: string
              length: 255
          name:
              type: string
              length: 255
  </code></pre>
  
  <p>AttrValue.orm.yml:</p>
  
  <pre><code>AppBundle\Entity\AttrValue:
      type: entity
      manyToOne:
          item:
              targetEntity: AppBundle\Entity\Item
              inversedBy: itemValues
              joinColumn:
                  nullable: true
          attribute:
              targetEntity: AppBundle\Entity\Attribute
              inversedBy: attrValues
              joinColumn:
                  nullable: true
      table: null
      repositoryClass: AppBundle\Repository\AttrValueRepository
      id:
          id:
              type: integer
              id: true
              generator:
                  strategy: AUTO
      fields:
          value:
              type: string
              length: 255
  </code></pre>
  
  <p>But when I want to get all the attributes from one item (or all items), then I get this JSON array:</p>
  
  <pre><code>{
      "id": 1,
      "name": "bike",
      "item_values": [
          {
              "id": 1,
              "value": "30",
              "attribute": {
                  "id": 1,
                  "alias": "size",
                  "name": "size",
                  "attr_values": []
              }
          }
      ]
  }
  </code></pre>
  
  <p>But I want to get something like this, how can this be done?</p>
  
  <pre><code>{
      "id": 1,
      "name": "bike",
      "attributes": [
              {
                  "id": 1,
                  "alias": "size",
                  "name": "size",
                  "attr_values": [
                            {
                            "id": 1,
                            "value": "30"
                            }
                    ]
              }
      ]
  }
  </code></pre>