                                            metaOnly: false,
                                            objectType: MSObjectType.purchaseorder,
                                            collectionName: "purchaseOrders")
-        dict["demands"] = serialize(entities: demands.flatMap { $0 as? MSDocument }.map { MSEntity<MSDocument>.entity($0) },
+        dict["demands"] = serialize(entities: demands.compactMap { $0 as? MSDocument }.map { MSEntity<MSDocument>.entity($0) },
                                     parent: self,
                                     metaOnly: true,
                                     objectType: MSObjectType.demand,

                                     metaOnly: false,
                                     objectType: MSObjectType.paymentin,
                                     collectionName: "payments")
        dict["invoicesOut"] = serialize(entities: invoicesOut.flatMap { $0 as? MSDocument }.map { MSEntity<MSDocument>.entity($0) },
                                        parent: self,
                                        metaOnly: true,
                                        objectType: MSObjectType.invoiceout,

                                    collectionName: "returns")
        dict["operations"] = serialize(entities: operations,
                                       parent: self,
                                       objectType: MSObjectType.customerorder,
                                       collectionName: "operations",
                                       serializeObject: { $0.metaAndLinkedSumDictionary() })
        dict["customerOrders"] = serialize(entities: customerOrders,
                                           parent: self,
                                           objectType: MSObjectType.customerorder, collectionName: "customerOrders")
