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

Typeorm .loadRelationCountAndMap 返回零

Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
本文介紹了Typeorm .loadRelationCountAndMap 返回零的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

請(qǐng)幫忙.我正在嘗試執(zhí)行以下 typeorm 查詢(xún):

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();

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

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 實(shí)體中保持計(jì)數(shù):

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 查詢(xún)中沒(méi)有看到任何選擇這些計(jì)數(shù)的嘗試,因此我希望 typeorm 本身可以進(jìn)行計(jì)數(shù)(因?yàn)樗_選擇了集合).

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).

有人可以就如何選擇這些計(jì)數(shù)提供一些建議嗎?

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

推薦答案

不幸的是 Typeorm 是最無(wú)能的框架.所有重要功能都已棄用或未實(shí)現(xiàn).

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

為了解決這個(gè)特定問(wèn)題,我必須:

To solve this particular issue i had to:

  1. 選擇集合本身:

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

  1. 添加計(jì)算和冗余關(guān)系數(shù)組刪除:

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

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

  1. 決定永遠(yuǎn)不再使用 TypeORM.

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

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

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類(lèi)型來(lái)存儲(chǔ)字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類(lèi)型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數(shù)據(jù))
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應(yīng)該返回“1?什么時(shí)候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱(chēng)轉(zhuǎn)換為其整數(shù)表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉(zhuǎn)換為 mm/dd/yyyy?)
主站蜘蛛池模板: 日韩在线播放av | 91视频18 | 亚洲一区二区三区四区五区午夜 | 国产一伦一伦一伦 | 奇米久久 | 午夜视频一区 | 福利片在线看 | 国产一级精品毛片 | 国产欧美精品一区二区三区 | 中文字幕日本一区二区 | 激情欧美日韩一区二区 | 午夜影院在线观看 | 韩国毛片一区二区三区 | 成人黄色三级毛片 | 在线视频亚洲 | 精品一区二区三区在线观看国产 | 日日噜噜噜夜夜爽爽狠狠视频97 | 国产精品日韩欧美一区二区三区 | 日韩精品一区二区三区中文在线 | 久草视频在 | 国产欧美在线视频 | 影音先锋欧美资源 | 国产一区二区在线免费观看 | 久久久久久久久久久福利观看 | 在线一区 | 国产精品欧美一区二区 | 99视频在线| 日韩精品一区二区三区 | 九色在线观看 | 亚洲一区二区三区在线免费观看 | 午夜网| 91久久综合亚洲鲁鲁五月天 | 观看av| 国产伦精品一区二区三区四区视频 | 欧美午夜精品久久久久久浪潮 | 国产亚洲精品久久情网 | 99国产精品99久久久久久 | 亚洲精选一区二区 | 欧美日韩视频在线第一区 | h视频在线观看免费 | 亚洲精品久久久久avwww潮水 |