title: Single table inheritance with relation targeting base class in TypeORM
body: <p>In my app, I want user to have notification items (news) of different type. <code>User</code> and <code>NewsItem</code> must have one-to-many relationship, but also, <code>NewsItem</code> is just a base class for the different types of actual news items.</p>
  
  <p>Here's my base <code>NewsItem</code> class:</p>
  
  <pre><code>@Entity()
  @TableInheritance({ column: { type: "varchar", name: "type"}})
  export class NewsItem {
  
      @PrimaryGeneratedColumn()
      id: number;
  
      @ManyToOne(type =&gt; User, user =&gt; user.news)
      receiver: Promise&lt;User&gt;;
  
  }
  </code></pre>
  
  <p>Here's the <code>User</code> it's attached to:</p>
  
  <pre><code>@Entity()
  export class User {
  
      @PrimaryGeneratedColumn()
      id: number;
  
      // (a lot of irrelevant stuff removed)
  
      @OneToMany(type =&gt; NewsItem, newsItem =&gt; newsItem.receiver)
      news: Promise&lt;NewsItem[]&gt;;
  
  }
  </code></pre>
  
  <p>And here's an example of a concrete news item:</p>
  
  <pre><code>@ChildEntity()
  export class ConcreteNewsItem extends NewsItem {
  
      @Column()
      someData: number;
  }
  </code></pre>
  
  <p>It all seems straightfoward enough from the documentation. Here's what I don't get, however: <strong>how do I go through a user's <code>news</code>, check what exact type each of them is, and get an object of a concrete news item type for each of them?</strong></p>
  
  <p>As I understand it, TypeORM will create a column called <code>type</code> in SQL definition of <code>news_item</code> table - but this column is not available on <code>NewsItem</code> class itself, and I can't understand how to build a query that would actually give me the <code>ConcreteNewsItem</code> objects!</p>