fictionco / fiction

(Join Waiting List) Personal Marketing Platform. A powerful platform for your online identity.
https://www.fiction.com
1.42k stars 109 forks source link

Idea: schemaPopulated should support nested/arrayed object values #261

Closed bppdddqqqq closed 2 years ago

bppdddqqqq commented 3 years ago

Reason for this idea

Current schemaPopulated only allows to pre-populate two specific schema definitions

example:

{
    goodOne: {ref: "attachment", type: ObjectId},
    goodOnes: [{ref: "attachment", type: ObjectId}],
    badObject: {
        badOne: {ref: "attachment", type: ObjectId},
    },
    badArrays: [{
        badOne: {ref: "attachment", type: ObjectId}
    }]
}

goodOne and goodOnes will pass by setting schemaPopulated: ["goodOne", "goodOnes"], but the remaining two cannot be populated by limited implementation of requestPostPopulate function. The code in question is in lines 80-89, which only picks object items via bracket notation and not via some parser...

The reason why the current implementation can be insufficient is when if it were used with "Sortable Inputs" form component. Adding an attachment form item will end up with broken behaviour (this reflects badArrays case). For "badObject" this can be reflected in nested objects used for readability reasons...

Proposed modification

Expand the function to support other possible cases.