1amageek / pring.ts

Cloud Firestore model framework for TypeScript - Google
https://firebase.google.com/docs/firestore/
MIT License
108 stars 7 forks source link

Nested ReferenceCollections are not saved #4

Closed starhoshi closed 6 years ago

starhoshi commented 6 years ago
class POrder extends Pring.Base {
  // user: Reference<PringUser>
  amount: number
  orderAddresses: Pring.ReferenceCollection<POrderAddress> = new Pring.ReferenceCollection(new POrderAddress())
}

class POrderAddress extends Pring.Base {
  amount: number
  orderShops: Pring.ReferenceCollection<POrderShop> = new Pring.ReferenceCollection(new POrderShop())
}

class POrderShop extends Pring.Base {
  amount: number
  orderSKUs: Pring.ReferenceCollection<POrderSKU> = new Pring.ReferenceCollection(new POrderSKU())
}

class POrderSKU extends Pring.Base {
  quantity: number
}
    const orderSKU = new POrderSKU()
    orderSKU.quantity = 1

    const orderShop = new POrderShop()
    orderShop.amount = 1000
    orderShop.orderSKUs.insert(orderSKU)

    const orderAddress = new POrderAddress()
    orderAddress.amount = 1000
    orderAddress.orderShops.insert(orderShop)

    const order = new POrder()
    order.amount = 1000
    order.orderAddresses.insert(orderAddress)

    order.save()

order, orderAddress, orderShop, orderSKU が同時に保存されると思ったのですが、 保存されたのは order, orderAddress だけでした :cry:

starhoshi commented 6 years ago

fixed this issue, thanks!

ref: https://github.com/1amageek/pring.ts/commit/74276895891d7d26ed8cf17d82e0bf211a85200e