typeorm - 多次指定 typeorm 表名
问题描述
我有下一个查询:
const foundDeal: any = await dealRepository.findOne({
where: { id: dealId },
relations: ['negotiationPointsDeals', 'chosenInventoryToSubtractQuantity',
'chosenInventoryToSubtractQuantity.inventoryItemType',
'chosenInventoryToSubtractQuantity.inventoryItemType.quality', 'negotiationPointsDeals.negotiationPointsTemplate',
'chosenInventoryToSubtractQuantity.addressOfOriginId', 'chosenInventoryToSubtractQuantity.currentLocationAddress',
'chosenInventoryToSubtractQuantity.labAttestationDocs',
'chosenInventoryToSubtractQuantity.labAttestationDocs.storage',
'chosenInventoryToSubtractQuantity.proveDocuments', 'chosenInventoryToSubtractQuantity.proveDocuments.storage',
'chosenInventoryToSubtractQuantity.inventoryItemSavedFields', 'chosenInventoryToSubtractQuantity.inventoryItemSavedFields.proveDocuments',
'chosenInventoryToSubtractQuantity.inventoryItemSavedFields.proveDocuments.storage',
'sellerBroker', 'sellerBroker.users',
'seller', 'seller.users',
'buyerBroker', 'buyerBroker.users',
'buyer', 'buyer.users',
'order', 'order.inventory', 'order.inventory.inventoryItemType',
'order.inventory.inventoryItemType.quality',
'order.inventory.addressOfOriginId', 'order.inventory.currentLocationAddress',
'order.inventory.inventoryItemSavedFields', 'order.inventory.inventoryItemSavedFields.proveDocuments',
'order.inventory.inventoryItemSavedFields.proveDocuments.storage',
'order.inventory.labAttestationDocs', 'order.inventory.labAttestationDocs.storage',
// 'postTradeProcessingDeal', 'postTradeProcessingDeal.postTradeProcessingStepsDeal',
'order.inventory.proveDocuments',
'order.inventory.proveDocuments.storage',
'negotiationPointsDeals.negotiationPointsTemplate.negotiationPointsTemplateChoices',
'postTradeProcessing',
],
});
所以,错误是下一个:
错误:多次指定表名“Deal__chosenInventoryToSubtractQuantity_Deal__chosenInventoryTo”。
但我在查询中看不到任何双打。
解决方案
此 TypeORM 问题中记录了该问题。
经过一番挖掘,我意识到这个错误是由于 TypeORM 在使用比 Postgres 名称限制长的预先加载时创建了某种变量。
例如,如果您急切地加载带有 customer 的产品,typeorm 将创建一些类似于 customer_products 的内容,将两者连接起来。如果该名称超过 63 个字节(Postgres 限制),则查询将崩溃。
基本上,当您的变量名太长或嵌套过多时,就会发生这种情况。使您的实体名称更短,它将起作用。否则,您可以使用手动连接表queryBuilder
并为其分配别名。
推荐阅读
- wpf - 我可以将区域放在 TabItem 控件中吗?
- sql - SQL Server - 选择每个月的每日值
- appium - 回退到直接的 W3C 远程端连接和 SessionNotCreatedException:无法创建新的远程会话
- reactjs - 如何在 React JS 中访问其他组件或服务中的应用程序组件的方法
- python - 为什么不推断所有静态类型?
- intellij-idea - VScode 相当于 Jetbrains/IntelliJ/Rubymine 划痕(一次性笔记)
- wordpress - 添加许多变体后,我的 woocommerce 产品页面太慢了
- azure - Azure:在 Node JS/Power shell 脚本中获取分配给企业应用程序的用户?
- javascript - 在 Vue 代码中使用 javascript 库/插件
- apache-kafka - Kafka 动态添加 SASL 用户,无需重启集群