forest-express-mongoose icon indicating copy to clipboard operation
forest-express-mongoose copied to clipboard

[+] Forms - Embedded arrays containing "deep" embedded documents are json inputs

Open Listu opened this issue 7 years ago • 7 comments
trafficstars

Expected behavior

Display array of embedded documents as related data

Actual behavior

Displayed as json in the parent document

Context

I have a Society with an array of Member embedded. Members are displayed in "details" and not in Related Data. I tried to create a fake field as a workaround with:

{ field: '_members', type: ['String'], reference: 'Society.members' }

but it try to display societies (whereas I guessed the model put in Liana.ResourceSerializer(Liana, Member... would say to forest "hey it's a Member")

  • Package Version: 2.13.1
  • Express Version: 4.15.4
  • Mongoose Version: 4.10.8
  • MongoDB Version: 3.4.9

Listu avatar Sep 06 '18 09:09 Listu

Hi @Listu, we'll look at your issue next week!

arnaudbesnier avatar Sep 14 '18 07:09 arnaudbesnier

Hey @Listu we were wondering if you could give us a sample of data you had in your database. A Society document with the embedded members. Thanks !

root-io avatar Sep 20 '18 12:09 root-io

Of course @root-io Hope it helps !

` {

    "_id" : ObjectId("5b8fde138e931929505a087a"),
    "updatedAt" : ISODate("2018-09-17T09:11:03.086Z"),
    "createdAt" : ISODate("2018-09-05T13:45:56.398Z"),
    "name" : "SPT",
    "address" : {
            "place_id" : "ChIJfXRynsNv5kcRZ9ypL-zaaoI",
            "country" : "France",
            "city" : "Paris",
            "area" : "Paris",
            "street" : "37 Rue Marbeuf",
            "postal_code" : "75008",
            "coordinates" : [
                    48.86967500000001,
                    2.305317000000059
            ],
            "_id" : ObjectId("5b8fde138e931929505a0882")
    },
    "invitations" : [ ],
    "status" : 0,
    "stripe" : "**************",
    "billingFrequency" : 2,
    "billings" : [
            {
                    "_id" : ObjectId("5b8fde138e931929505a0878"),
                    "address" : {
                            "place_id" : "ChIJfXRynsNv5kcRZ9ypL-zaaoI",
                            "country" : "France",
                            "city" : "Paris",
                            "area" : "Paris",
                            "street" : "37 Rue Marbeuf",
                            "postal_code" : "75008",
                            "coordinates" : [
                                    48.86967500000001,
                                    2.305317000000059
                            ],
                            "_id" : ObjectId("5b8fde138e931929505a0879")
                    },
                    "nic" : "63214",
                    "siren" : "123654789",
                    "capital" : 15000,
                    "raison" : "SPT",
                    "service" : null
            },
            {
                    "_id" : ObjectId("5b9f6ee870be0f42d0a0384e"),
                    "address" : {
                            "place_id" : "ChIJfXRynsNv5kcRZ9ypL-zaaoI",
                            "city" : "Paris",
                            "area" : "Paris",
                            "country" : "France",
                            "postal_code" : "75008",
                            "street" : "37 Rue Marbeuf",
                            "coordinates" : [
                                    48.86967500000001,
                                    2.305317000000059
                            ],
                            "_id" : ObjectId("5b9f6ee870be0f42d0a0384f")
                    },
                    "capital" : 10000,
                    "nic" : "12355",
                    "siren" : "123456789",
                    "raison" : "TEST",
                    "service" : "Yolo"
            }
    ],
    "members" : [
            {
                    "updatedAt" : ISODate("2018-09-05T13:45:56.396Z"),
                    "createdAt" : ISODate("2018-09-05T13:45:56.396Z"),
                    "user" : ObjectId("5b8fde128e931929505a085d"),
                    "billing" : ObjectId("5b8fde138e931929505a0878"),
                    "politic" : {
                            "_id" : ObjectId("5b8fdd468e931929505a0776"),
                            "rental" : {
                                    "maxprice" : 100
                            },
                            "price" : {
                                    "min" : 0,
                                    "max" : 500,
                                    "_id" : ObjectId("5b8fdd468e931929505a0777")
                            },
                            "stars" : {
                                    "min" : 1,
                                    "max" : 5,
                                    "_id" : ObjectId("5b8fdd468e931929505a0778")
                            }
                    },
                    "_id" : ObjectId("5b8fde138e931929505a087b"),
                    "roles" : [
                            "executive"
                    ]
            },
            {
                    "updatedAt" : ISODate("2018-09-17T09:11:03.085Z"),
                    "createdAt" : ISODate("2018-09-17T09:10:52.029Z"),
                    "user" : ObjectId("5b9f6f9b70be0f42d0a03881"),
                    "politic" : {
                            "flight" : {
                                    "price" : {
                                            "max" : 1100,
                                            "min" : 0
                                    },
                                    "class" : "business"
                            },
                            "_id" : ObjectId("5b9f6fa770be0f42d0a03aac"),
                            "rental" : {
                                    "maxprice" : 100
                            },
                            "price" : {
                                    "min" : 0,
                                    "max" : 500,
                                    "_id" : ObjectId("5b9f6fa770be0f42d0a03aad")
                            },
                            "stars" : {
                                    "min" : 2,
                                    "max" : 5,
                                    "_id" : ObjectId("5b9f6fa770be0f42d0a03aae")
                            }
                    },
                    "billing" : ObjectId("5b9f6ee870be0f42d0a0384e"),
                    "_id" : ObjectId("5b9f6f9c70be0f42d0a03888"),
                    "roles" : [
                            "traveler"
                    ]
            }
    ],
    "__v" : 1

} `

Listu avatar Sep 20 '18 13:09 Listu

Hi @Listu, this is currently a limitation of our platform.

In the case of arrays of embedded document that contain only keys/values with a "single depth level", these arrays will appear in the "Related Data" section.

For more complex documents in embedded arrays, as the edition may be very complex, we display a JSON field to manipulate the data. This is clearly not an ideal usage, but at least you can read and manipulate the data. We definitely need to work on this.

arnaudbesnier avatar Sep 25 '18 13:09 arnaudbesnier

Ok so we have to change our model, wait an improvement or dev our own dashboard. Thank you for the help.

Listu avatar Sep 25 '18 13:09 Listu

Any news on this ?

roonie007 avatar Oct 21 '18 20:10 roonie007

We have the same problem over here. Actually this can be solved with a smart collection of sub-documents, with a one-to-many relationship between the parent document and the sub-documents, by implementing the json-api. The "id" of each subdocument should contain both the the id of the parent document and the id of the sub-document to avoid collisions between two sub-documents with the same id that reside in two different parent documents. This can be skipped if the sub-documents' ids are unique (i.e. when they are autogenerated by mongoose). Also, each subdocument should have a reference to its exactly-one parent document, and an index for its position inside the parent document array. The references themselves the be implemented with Liana smart relationships. Paging can also be a non-trivial because of the ordering. It could be solved by sorting the subdocuments first by the parent-id and then by their own subdocument-id.

Flattening all the models could annoying, especially if you are actually modeling a tree structure, i.e. "Project" containing an array of "Sections", containing an array of "Tasks". This is one of the greatest advantages of NoSql - you can simply load the document with Robo3t or other clients, load the document, and see the tree-structure without needing to write code for populating all the arrays of references.

ozomer avatar Dec 11 '18 09:12 ozomer