hola-server 0.3.13 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db/entity.js +29 -12
- package/package.json +1 -1
package/db/entity.js
CHANGED
|
@@ -633,7 +633,7 @@ class Entity {
|
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
//check all the ref by array first
|
|
636
|
-
const has_refer_by_array = await this.check_refer_entity(id_array);
|
|
636
|
+
const has_refer_by_array = await this.check_refer_entity(this.meta.collection, id_array, id_array);
|
|
637
637
|
if (has_refer_by_array.length > 0) {
|
|
638
638
|
const array = [...new Set(has_refer_by_array)];
|
|
639
639
|
if (is_log_error()) {
|
|
@@ -802,12 +802,12 @@ class Entity {
|
|
|
802
802
|
}
|
|
803
803
|
|
|
804
804
|
/**
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
async check_refer_entity(id_array) {
|
|
805
|
+
*
|
|
806
|
+
* @param {the original collection name} collection
|
|
807
|
+
* @param {the id array used to check} id_array
|
|
808
|
+
* @returns refer by entities
|
|
809
|
+
*/
|
|
810
|
+
async check_refer_entity(collection, collection_id_array, id_array) {
|
|
811
811
|
const has_refer_by_array = [];
|
|
812
812
|
for (let i = 0; i < this.meta.ref_by_metas.length; i++) {
|
|
813
813
|
const ref_by_meta = this.meta.ref_by_metas[i];
|
|
@@ -825,15 +825,32 @@ class Entity {
|
|
|
825
825
|
const entities = await refer_by_entity.get_refer_entities(ref_field.name, id_array, attr);
|
|
826
826
|
if (entities && entities.length > 0) {
|
|
827
827
|
if (ref_field.delete == DELETE_MODE.cascade) {
|
|
828
|
-
const ref_array = await refer_by_entity.check_refer_entity(entities.map(o => o._id + ""));
|
|
828
|
+
const ref_array = await refer_by_entity.check_refer_entity(collection, collection_id_array, entities.map(o => o._id + ""));
|
|
829
829
|
if (ref_array && ref_array.length > 0) {
|
|
830
830
|
has_refer_by_array.push(...ref_array);
|
|
831
831
|
}
|
|
832
832
|
} else {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
833
|
+
const ref_collection_fields = ref_by_meta.ref_fields.filter(field => field.ref == collection && field.delete == DELETE_MODE.cascade);
|
|
834
|
+
const ref_entities_ids = [];
|
|
835
|
+
const left_entities = [];
|
|
836
|
+
for (let k = 0; k < ref_collection_fields.length; k++) {
|
|
837
|
+
const ref_collection_field = ref_collection_fields[k];
|
|
838
|
+
const ref_collection_entities = await refer_by_entity.get_refer_entities(ref_collection_field.name, collection_id_array, attr);
|
|
839
|
+
ref_collection_entities && ref_collection_entities.length > 0 && ref_entities.push(...(ref_collection_entities.map(o => o["_id"] + "")));
|
|
840
|
+
}
|
|
841
|
+
for (let k = 0; k < entities.length; k++) {
|
|
842
|
+
const entity = entities[k];
|
|
843
|
+
if (!ref_entities_ids.includes(entity["_id"] + "")) {
|
|
844
|
+
left_entities.push(entity);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
if (left_entities.length > 0) {
|
|
849
|
+
if (ref_by_meta.ref_label) {
|
|
850
|
+
has_refer_by_array.push(...entities.map(o => this.meta.collection + "<-" + ref_by_meta.collection + ":" + o[ref_by_meta.ref_label]));
|
|
851
|
+
} else {
|
|
852
|
+
has_refer_by_array.push(...entities.map(o => this.meta.collection + "<-" + ref_by_meta.collection + ":" + o["_id"] + ""));
|
|
853
|
+
}
|
|
837
854
|
}
|
|
838
855
|
}
|
|
839
856
|
}
|