title: TypeOrm Save One-To-Many Object Relation
body: <p>I have problem when trying to save object with one to many relation (mysql), it actually save only the top level entity. the generated query is</p>
  
  <p><code>INSERT INTO `SeceneTemplates`(`Id`, `Name`, `Address`, `Rows`, `Cols`) VALUES (DEFAULT, ?, ?, ?, ?) -- PARAMETERS: ["Pallati i Kongreseve","Sheshi Nene Tereza",5,5]</code></p>
  
  <p>I don't know if there am doing smth wrong</p>
  
  <p>it was supposed to generate three queries for each entity under a transaction
  sorry since I am new on node and TypeORM, possibly I have missed smth
  SeatsTemplate, ZoneTempalte and SeceneTemlate are entities and are loaded successfully.</p>
  
  <p><strong>SeceneTemplates.ts</strong></p>
  
  <pre><code>import { ZoneTemplates } from "./ZoneTemplates";
  import { Column, PrimaryGeneratedColumn, Entity, OneToMany } from "typeorm";
  
  @Entity("SeceneTemplates")
  export class SeceneTemplates {
    @PrimaryGeneratedColumn()
    Id: bigint;
    @Column()
    Name!: string;
    @Column()
    Address: string;
    @Column()
    Rows: number;
    @Column()
    Cols: number;
  
    @OneToMany(
      type =&gt; ZoneTemplates,
      zoneTemplate =&gt; zoneTemplate.sceneTemplate,
      { cascade: ["insert", "update", "remove"] }
    )
    zoneTemplates: ZoneTemplates[];
  
    public constructor(init?: Partial&lt;SeceneTemplates&gt;) {
      Object.assign(this, init);
    }
  }
  </code></pre>
  
  <p><strong>ZoneTemaplate.ts</strong></p>
  
  <pre><code>import { SeceneTemplates } from "./SeceneTemplates";
  import { SeatsTemplates } from "./SeatsTemplates";
  import {
    Column,
    PrimaryGeneratedColumn,
    Entity,
    ManyToOne,
    OneToMany
  } from "typeorm";
  
  @Entity("ZoneTemplates")
  export class ZoneTemplates {
    @PrimaryGeneratedColumn()
    Id: bigint;
    @Column()
    Name!: string;
    @Column()
    Description: string;
    @Column()
    ColorCode: string;
  
    @ManyToOne(
      type =&gt; SeceneTemplates,
      sceneTemplate =&gt; sceneTemplate.zoneTemplates,
      { cascade: ["insert", "update", "remove"] }
    )
    sceneTemplate: SeceneTemplates;
    @OneToMany(
      type =&gt; SeatsTemplates,
      seatsTemplate =&gt; seatsTemplate.zoneTemplate,
      { cascade: ["insert", "update", "remove"] }
    )
    seatsTemplates: SeatsTemplates[];
  
    public constructor(init?: Partial&lt;ZoneTemplates&gt;) {
      Object.assign(this, init);
    }
  }
  </code></pre>
  
  <p><strong>SeatsTemplates.ts</strong></p>
  
  <pre><code>import { SeceneTemplates } from "./SeceneTemplates";
  import { ZoneTemplates } from "./ZoneTemplates";
  import {
    Entity,
    Column,
    PrimaryColumn,
    PrimaryGeneratedColumn,
    ManyToOne
  } from "typeorm";
  
  @Entity("SeatsTemplates")
  export class SeatsTemplates {
    @PrimaryGeneratedColumn()
    Id: bigint;
    @Column()
    x: number;
    @Column()
    y: number;
  
    @ManyToOne(
      type =&gt; ZoneTemplates,
      zoneTemplate =&gt; zoneTemplate.seatsTemplates,
      { cascade: ["insert", "update", "remove"] }
    )
    zoneTemplate: ZoneTemplates;
  
    public constructor(init?: Partial&lt;SeatsTemplates&gt;) {
      Object.assign(this, init);
    }
  }
  </code></pre>
  
  <p><strong>SceneService</strong></p>
  
  <pre><code>import { ISceneService } from "../interfaces/ISceneService";
  import { CreateSceneRequestDTO } from "../../models/dto/Scenes/CreateSceneRequestDTO";
  import { CreateSceneResponseDTO } from "../../models/dto/Scenes/CreateSceneResponseDTO";
  import { SeceneTemplates } from "../../models/data/SeceneTemplates";
  import { ZoneTemplates } from "../../models/data/ZoneTemplates";
  import { SeatsTemplates } from "../../models/data/SeatsTemplates";
  import { createConnection, getConnectionManager } from "typeorm";
  
  export class SceneService implements ISceneService {
    createScene(request: CreateSceneRequestDTO): Promise&lt;CreateSceneResponseDTO&gt; {
      return new Promise&lt;CreateSceneResponseDTO&gt;(async (resolve, rejects) =&gt; {
        let createSceneResponse: CreateSceneResponseDTO = new CreateSceneResponseDTO(
          {
            code: "999",
            message: "Internal Server Error",
            success: false
          }
        );
  
        const connection = getConnectionManager().get("default");
  
        const eventRepository = connection.getRepository(SeceneTemplates);
  
        let newSceneTemplate = new SeceneTemplates({
          Name: request.sceneName,
          Rows: request.rows,
          Cols: request.columns,
          Address: request.address
        });
  
        let newZoneTemplates = request.areas.map(val =&gt; {
          return new ZoneTemplates({
            ColorCode: val.color,
            Name: val.name,
            Description: val.description,
            sceneTemplate: newSceneTemplate
          });
        });
  
        newZoneTemplates.forEach((v, k) =&gt; {
          newZoneTemplates[k].seatsTemplates = request.seats
            .filter(e =&gt; e.color === v.ColorCode)
            .map(seatVal =&gt; {
              return new SeatsTemplates({
                x: seatVal.x,
                y: seatVal.y,
                zoneTemplate: v
              });
            });
        });
  
        newSceneTemplate.zoneTemplates = newZoneTemplates;
  
        eventRepository
          .save(newSceneTemplate)
          .then((currentScene: SeceneTemplates) =&gt; {
            createSceneResponse.message = "Success";
            createSceneResponse.code = "200";
            createSceneResponse.success = true;
            createSceneResponse.SceneId = currentScene.Id;
  
            resolve(createSceneResponse);
          })
          .catch(err =&gt; {
            createSceneResponse.message = "Failed to save the scene";
            createSceneResponse.code = "500";
            createSceneResponse.success = false;
  
            rejects(createSceneResponse);
          });
      });
    }
  }
  </code></pre>