久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Typeorm .loadRelationCountAndMap 返回零

Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
本文介紹了Typeorm .loadRelationCountAndMap 返回零的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

請幫忙.我正在嘗試執行以下 typeorm 查詢:

please help. I am trying to execute the following typeorm query:

  return await getRepository(Company)
    .createQueryBuilder("Company")
    .leftJoinAndSelect("Company.plants", "Plant")
    .leftJoinAndSelect("Plant.documents", "Document")
    .leftJoinAndSelect("Plant.notes", "Note")
    .loadRelationCountAndMap("Plant.documentsCount", "Plant.documents")
    .loadRelationCountAndMap("Plant.notesCount", "Plant.notes")
    .getMany();

我們的想法是選擇每個工廠以及所有公司的所有工廠的文檔和筆記數量.(實際上不需要自己選擇筆記和文件,但我這樣做是為了證明關系確實有效).

The idea was to select counts of documents and notes per each plant along with all plants for all companies. (Actually selecting notes and documents themselves was not needed, but i did it to prove that relations do work).

此外,我還指定了占位符變量以在 Plant 實體中保持計數:

Also I have specified the placeholder variables to keep counts in Plant entity:

  @OneToMany(() => Document, (document) => document.plant)
  documents: Document[];
  documentsCount: number;

  @OneToMany(() => Note, (note) => note.plant)
  notes: Note[];
  notesCount: number;

奇怪的是返回的Plant.documentsCount和Plant.notesCount都是0(而文檔和筆記的集合不是空的,正在被選中).

Strangely the returned Plant.documentsCount and Plant.notesCount are 0 (while the collections of documents and notes are not empty and are being selected).

另一件奇怪的事情是,我在 SQL 查詢中沒有看到任何選擇這些計數的嘗試,因此我希望 typeorm 本身可以進行計數(因為它正確選擇了集合).

Another strange thing is that i don't see in SQL querires any attempts to select these counts, thus i hope typeorm itself would do counting (since it has collections selected correctly).

有人可以就如何選擇這些計數提供一些建議嗎?

Could anybody please give some advise on how to select these counts?

推薦答案

不幸的是 Typeorm 是最無能的框架.所有重要功能都已棄用或未實現.

Unfortunately Typeorm is the most impotent framework. All important features are either deprecated or not implemented.

為了解決這個特定問題,我必須:

To solve this particular issue i had to:

  1. 選擇集合本身:

   .leftJoinAndSelect("Plant.documents", "Document")
   .leftJoinAndSelect("Plant.notes", "Note")

  1. 添加計算和冗余關系數組刪除:

  @AfterLoad()
  getDocumentsCount() {
    this.documentsCount = this.documents.length;
    delete this.documents;
  }

  @AfterLoad()
  getNotesCount() {
    this.notesCount = this.notes.length;
    delete this.notes;
  }

  1. 決定永遠不再使用 TypeORM.

這篇關于Typeorm .loadRelationCountAndMap 返回零的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉換為其整數表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉換為 mm/dd/yyyy?)
主站蜘蛛池模板: 久久国产精品网 | 一区二区三区在线免费观看 | 一级欧美一级日韩片 | 人人干超碰 | 成人免费共享视频 | 久久亚洲免费 | 亚洲成人精品国产 | 欧美久久一级特黄毛片 | 国产精品美女久久久久久免费 | 国产高清在线精品 | 欧美精品一区二区三区在线 | 91色视频在线 | 国产精品美女久久久久aⅴ国产馆 | 久久国产精品久久久久久久久久 | 精品国产精品国产偷麻豆 | 久久久久亚洲精品国产 | 色性av | 久久久www成人免费精品 | 中文字幕在线精品 | 99精品国产一区二区青青牛奶 | 国产精品久久久久久久久久免费 | 精品久久久久久久久亚洲 | 国产精品国产三级国产aⅴ无密码 | www.久久久久久久久 | 成人久草| 日韩欧美国产精品一区二区三区 | 请别相信他免费喜剧电影在线观看 | 中文字幕精品一区 | 国产精品欧美精品日韩精品 | 国产在线视频三区 | 97人人澡人人爽91综合色 | 麻豆久久久 | 欧美三级电影在线播放 | 久色网 | 久久精品一级 | 97狠狠干 | 国产婷婷 | 91免费电影 | 国产成人精品综合 | 一级黄色在线 | 99精品国产一区二区青青牛奶 |