hola-server 0.3.15 → 0.3.16
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 +7 -25
- 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(
|
|
636
|
+
const has_refer_by_array = await this.check_refer_entity(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()) {
|
|
@@ -803,11 +803,10 @@ class Entity {
|
|
|
803
803
|
|
|
804
804
|
/**
|
|
805
805
|
*
|
|
806
|
-
* @param {the original collection name} collection
|
|
807
806
|
* @param {the id array used to check} id_array
|
|
808
807
|
* @returns refer by entities
|
|
809
808
|
*/
|
|
810
|
-
async check_refer_entity(
|
|
809
|
+
async check_refer_entity(id_array) {
|
|
811
810
|
const has_refer_by_array = [];
|
|
812
811
|
for (let i = 0; i < this.meta.ref_by_metas.length; i++) {
|
|
813
812
|
const ref_by_meta = this.meta.ref_by_metas[i];
|
|
@@ -825,32 +824,15 @@ class Entity {
|
|
|
825
824
|
const entities = await refer_by_entity.get_refer_entities(ref_field.name, id_array, attr);
|
|
826
825
|
if (entities && entities.length > 0) {
|
|
827
826
|
if (ref_field.delete == DELETE_MODE.cascade) {
|
|
828
|
-
const ref_array = await refer_by_entity.check_refer_entity(
|
|
827
|
+
const ref_array = await refer_by_entity.check_refer_entity(entities.map(o => o._id + ""));
|
|
829
828
|
if (ref_array && ref_array.length > 0) {
|
|
830
829
|
has_refer_by_array.push(...ref_array);
|
|
831
830
|
}
|
|
832
831
|
} else {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
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_ids.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(...left_entities.map(o => this.meta.collection + "<-" + ref_by_meta.collection + ":" + o[ref_by_meta.ref_label]));
|
|
851
|
-
} else {
|
|
852
|
-
has_refer_by_array.push(...left_entities.map(o => this.meta.collection + "<-" + ref_by_meta.collection + ":" + o["_id"] + ""));
|
|
853
|
-
}
|
|
832
|
+
if (ref_by_meta.ref_label) {
|
|
833
|
+
has_refer_by_array.push(...entities.map(o => this.meta.collection + "<-" + ref_by_meta.collection + ":" + o[ref_by_meta.ref_label]));
|
|
834
|
+
} else {
|
|
835
|
+
has_refer_by_array.push(...entities.map(o => this.meta.collection + "<-" + ref_by_meta.collection + ":" + o["_id"] + ""));
|
|
854
836
|
}
|
|
855
837
|
}
|
|
856
838
|
}
|