首页 > 解决方案 > 我想在 Fire 商店中创建客户集合,并且我希望发票与 firebase 中的该集合相关联

问题描述

客户:[{名称:“helloWorld”,电话:123,地址:“address1”,发票:[{ product1:“sa”,价格:“4500”,totalAmount:123,},{ product1:“Bca”,价格:"2600", totalAmount:2500, } ]

},

{名称:“NewCus”,电话:788888888,地址:“address2”,发票:[{ product1:“ase2”,价格:“6500”,totalAmount:9000,},{ product1:“Bca”,价格:“bha ", 总金额:2500, } ]

}

],

标签: firebasegoogle-cloud-firestore

解决方案


有很多方法可以做到这一点。一种选择是从用户集合开始

users
   uid_0 //john's uid from their auth object
      name: "John"
   uid_1
      name: "Paul"

然后发票存储在发票集合中,并引用用户 uid

invoices
  invoice_0
     amount: "$100"
     user: "uid_0"
  invoice_1
     amount: "$50"
     user: "uid_0"
  invoice_2
     amount: "$22"
     user: "uid_1"

综上所述,用户 John 有两张发票;100 美元和 50 美元,uid_1 在发票上有一张 22 美元

根据您要运行的查询,您还可以在用户文档中存储用户发票列表。

users
   uid_0 //john's uid from their auth object
      name: "John"
      invoices:
         invoice_0: true //true is a placeholder value
         invoice_1: true

推荐阅读