scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
557 stars 81 forks source link

Support for reference document inside embedded document #107

Open ofirbw opened 7 years ago

ofirbw commented 7 years ago

Hi there,

Why there is no support for reference document inside an embedded document? it's just take the whole data instead of what i expected to save which is the embedded data along with the id for the reference document. ` // Replace EmbeddedDocument references with just their data _.keys(that._schema).forEach(function(key) { if (isEmbeddedDocument(that[key]) || // isEmbeddedDocument OR (isArray(that[key]) && // isArray AND contains value AND value isEmbeddedDocument that[key].length > 0 && isEmbeddedDocument(that[key][0]))) {

                // Handle array of references (ex: { type: [MyObject] })
                if (isArray(that[key])) {
                    toUpdate[key] = [];
                    that[key].forEach(function(v) {
                        toUpdate[key].push(v._toData());
                    });
                } else {
                    toUpdate[key] = that[key]._toData();
                }

            }
        });`

The line toUpdate[key].push(v._toData()); just take the whole data, can I replace this with the _id of the document and handle the read part or this is a bad approach?

Thanks!