Help with firebase document retrieve data

@Mohammed2021 I may have solved your problem :crossed_fingers:

I couldn’t find anywhere where you were updating your precious orderDetails property, nor adding orderDetails to the orderDetails property in the orderData object that you append to orderDatafb.

You add all of the other properties to the orderData object. In this long line:

self.orderDatafb.append(orderData(id: id, adress: adress, location: location, city: city, name: name, phone: phone, total: total))

I recommend breaking this line up, so it becomes clearer:

self.orderDatafb.append(
    orderData(
        id: id,
        adress: adress,
        location: location,
        city: city,
        name: name,
        phone: phone,
        total: total
    )
)

Notice anything missing? After the total property, you forgot to add the orderDetails property. So it should look like this instead:

self.orderDatafb.append(
    orderData(
        id: id,
        adress: adress,
        location: location,
        city: city,
        name: name,
        phone: phone,
        total: total,
        orderDetails: orderDetails
    )
)

Also, you never update the orderDetails property of the OrderDataModel. Honestly, this property is redundant, because your orderDatafb property already contains this same data as a list in one of its properties. Still, it’s easier to access the orderDetails by having it as a property as you do.

So to do this, you add the following line above before your for loop:

self.orderDetails = orderDetails

Also, when getting your orderDetails from Firebase, I recommend decoding it as an order type, versus the Any type of list. So you change this line:

let orderDetails = doc.get("order") as! [Any]

To:

let orderDetails = doc.get("order") as! [order]

Let me know, if this works! Thanks for posting example data, as well as all of this code, so far :slight_smile: Looks like this was a simple mistake, and it helps to have someone else review your code.

Cheers,
Andrew