我正在测试 Parse 本地数据存储,以评估我是否可以将它用作 SQLite 的替代品,用于主要离线使用的应用程序。我可能发现了一个错误?
考虑 Product 和 Order 类:
class Product : PFObject, PFSubclassing {
@NSManaged var productName: String!
}
class Order : PFObject, PFSubclassing {
@NSManaged var orderId: String!
@NSManaged var product: Product!
}
在禁用互联网的情况下,当我运行以下代码时,它会在最后一行崩溃Tried to save an object with a new, unsaved child.
let p = Product()
p.productName = "Test Product"
p.saveEventually()
let o = Order()
o.orderId = "TestOrder01"
o.product = p
o.saveEventually()
let query = Order.query()
query.whereKey("product", equalTo: p)
let results = query.findObjects() // crashes with Tried to save an object with a new, unsaved child.
是平台限制还是我的代码中的错误?
注意我已经从内存中输入了代码,所以忽略小问题。