You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Data Connect Schema中StorageType引用报错求助

Firebase Data Connect Schema 引用错误修复方案

错误原因

你遇到的引用错误是因为StorageType表的主键为复合键(name + store),而InventoryItemMetaData里的storageTypeName字段仅通过单一字段尝试引用它。Firebase Data Connect要求引用复合主键的表时,必须完整匹配所有主键字段,因此导致匹配失败。


解决方案

方案1:调整引用字段匹配复合主键

修改InventoryItemMetaData中的字段结构,通过@ref(fields)映射实现复合主键的关联(复用当前表已有的store字段):

type Store @table(key: "id") {
  id: String!                # Unique store ID
  name: String!              # Store name
  location: String           # Store location
  contactInfo: String        # Store contact info
}

type Category @table(key: ["name","store"]) {
  name: String!                       # Name of the Category (e.g. Drinks)
  store: Store! @ref                  # ID of the store this task belongs to
}

type StorageType @table(key: ["name","store"]){
  name: String!                       # Name of the Storage (e.g., DRY, Warehouse)
  store: Store! @ref                  # ID of the store this task belongs to
}

type Tag @table(key: ["name","store"]) {
  name: String!                       # Name of the product (e.g., Milk Tea)
  store: Store! @ref                  # ID of the store this task belongs to
}

type InventoryItemMetaData @table (key: ["sku","store"]) {
  id: UUID! @default(expr: "uuidV4()")
  name: String!
  sku: String!
  unit: String!
  lastUpdated: Timestamp! @default(expr: "request.time")
  threshold: Float            # minimum quantity we should have
  store: Store! @ref          # ID of the store this task belongs to
  category: Category @ref     # Used to categorize the inventory. Like Frozen, Dairy
  tags: [String]
  yield: Float @default(value: 100)
  storageTypeName: String! # 存储StorageType的name字段
  # 通过字段映射完成复合主键引用
  storageType: StorageType! @ref(fields: {name: "storageTypeName", store: "store"})
}

方案2:将StorageType改为单一主键(更简洁)

如果业务逻辑允许,把StorageType的主键改为单一id,和Store保持一致,简化引用逻辑:

type Store @table(key: "id") {
  id: String!                # Unique store ID
  name: String!              # Store name
  location: String           # Store location
  contactInfo: String        # Store contact info
}

type Category @table(key: ["name","store"]) {
  name: String!                       # Name of the Category (e.g. Drinks)
  store: Store! @ref                  # ID of the store this task belongs to
}

type StorageType @table(key: "id"){
  id: String! @default(expr: "uuidV4()") # 新增单一主键
  name: String!                       # Name of the Storage (e.g., DRY, Warehouse)
  store: Store! @ref                  # ID of the store this task belongs to
}

type Tag @table(key: ["name","store"]) {
  name: String!                       # Name of the product (e.g., Milk Tea)
  store: Store! @ref                  # ID of the store this task belongs to
}

type InventoryItemMetaData @table (key: ["sku","store"]) {
  id: UUID! @default(expr: "uuidV4()")
  name: String!
  sku: String!
  unit: String!
  lastUpdated: Timestamp! @default(expr: "request.time")
  threshold: Float            # minimum quantity we should have
  store: Store! @ref          # ID of the store this task belongs to
  category: Category @ref     # Used to categorize the inventory. Like Frozen, Dairy
  tags: [String]
  yield: Float @default(value: 100)
  storageTypeId: String! @ref(to: StorageType) # 直接引用单一主键
}

内容的提问来源于stack exchange,提问作者Priyatham51

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 06:33:15