@reldens/storage 0.10.0-beta.33 → 0.10.0-beta.34
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.
|
@@ -54,7 +54,7 @@ class MikroOrmDriver extends BaseDriver
|
|
|
54
54
|
|
|
55
55
|
async create(params)
|
|
56
56
|
{
|
|
57
|
-
let newInstance = this.rawModel.
|
|
57
|
+
let newInstance = this.rawModel.entity.createByProps(params);
|
|
58
58
|
await this.repository.persist(newInstance).flush();
|
|
59
59
|
return newInstance;
|
|
60
60
|
}
|
|
@@ -232,8 +232,11 @@ class MikroOrmDriver extends BaseDriver
|
|
|
232
232
|
async appendRelationsToCollection(entitiesCollection, relations)
|
|
233
233
|
{
|
|
234
234
|
// @TODO - BETA - Refactor. I would like to use populate but it may not work if the driver is not Mongo DB.
|
|
235
|
+
if(typeof this.rawModel.entity.relationsMappings !== 'function'){
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
235
238
|
if(!sc.isArray(relations) || 0 === relations.length){
|
|
236
|
-
relations = Object.keys(this.rawModel.relationsMappings || {});
|
|
239
|
+
relations = Object.keys(this.rawModel.entity.relationsMappings() || {});
|
|
237
240
|
}
|
|
238
241
|
if(0 === relations.length){
|
|
239
242
|
return entitiesCollection;
|
|
@@ -247,8 +250,12 @@ class MikroOrmDriver extends BaseDriver
|
|
|
247
250
|
async appendRelatedEntities(entity, relations)
|
|
248
251
|
{
|
|
249
252
|
// @TODO - BETA - Refactor and improve.
|
|
253
|
+
if(typeof this.rawModel.entity.relationsMappings !== 'function'){
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
let relationsMappings = typeof this.rawModel.entity.relationsMappings();
|
|
250
257
|
for(let i of relations){
|
|
251
|
-
let relation =
|
|
258
|
+
let relation = relationsMappings[i];
|
|
252
259
|
let relationRepository = this.server.getEntity(relation.entityName);
|
|
253
260
|
let isManyToOne = 'm:1' === relation.reference;
|
|
254
261
|
let isOneToMany = '1:m' === relation.reference;
|
|
@@ -263,14 +270,15 @@ class MikroOrmDriver extends BaseDriver
|
|
|
263
270
|
|
|
264
271
|
async createNested(newInstance, params)
|
|
265
272
|
{
|
|
266
|
-
if(
|
|
273
|
+
if(typeof this.rawModel.entity.relationsMappings !== 'function'){
|
|
267
274
|
return false;
|
|
268
275
|
}
|
|
269
|
-
|
|
276
|
+
let relationsMappings = this.rawModel.entity.relationsMappings();
|
|
277
|
+
for(let i of Object.keys(relationsMappings)){
|
|
270
278
|
// @TODO - BETA - Refactor and improve.
|
|
271
|
-
let relationData =
|
|
272
|
-
let
|
|
273
|
-
if(!
|
|
279
|
+
let relationData = relationsMappings[i];
|
|
280
|
+
let relationEntity = this.server.entityManager.get(relationData.entityName).rawModel.entity;
|
|
281
|
+
if(!relationEntity){
|
|
274
282
|
Logger.warning('Factory not found for relation definition:', relationData);
|
|
275
283
|
continue;
|
|
276
284
|
}
|
|
@@ -280,30 +288,30 @@ class MikroOrmDriver extends BaseDriver
|
|
|
280
288
|
if(!sc.hasOwn(params, relationData.join.from) || !params[relationData.join.from]){
|
|
281
289
|
continue;
|
|
282
290
|
}
|
|
283
|
-
await this.createOne(params, i,
|
|
291
|
+
await this.createOne(params, i, relationEntity, newInstance, relationData);
|
|
284
292
|
continue;
|
|
285
293
|
}
|
|
286
294
|
if(isOneToMany){
|
|
287
|
-
await this.createMany(params, i,
|
|
295
|
+
await this.createMany(params, i, relationEntity, newInstance, relationData);
|
|
288
296
|
}
|
|
289
297
|
}
|
|
290
298
|
}
|
|
291
299
|
|
|
292
|
-
async createOne(params, i,
|
|
300
|
+
async createOne(params, i, relationEntity, newInstance, relationData)
|
|
293
301
|
{
|
|
294
302
|
params[i] = newInstance[relationData.join.from];
|
|
295
|
-
let nestedObject =
|
|
303
|
+
let nestedObject = relationEntity.create(params[i]);
|
|
296
304
|
await this.repository.persist(nestedObject).flush();
|
|
297
305
|
await this.orm.em.flush();
|
|
298
306
|
newInstance[i] = nestedObject;
|
|
299
307
|
}
|
|
300
308
|
|
|
301
|
-
async createMany(params, i,
|
|
309
|
+
async createMany(params, i, relationEntity, newInstance, relationData)
|
|
302
310
|
{
|
|
303
311
|
let nestedArray = [];
|
|
304
312
|
for(let objectData of params[i]){
|
|
305
313
|
objectData[relationData.join.to] = newInstance[relationData.join.from];
|
|
306
|
-
let nestedObject =
|
|
314
|
+
let nestedObject = relationEntity.create(objectData);
|
|
307
315
|
await this.repository.persist(nestedObject).flush();
|
|
308
316
|
await this.orm.em.flush();
|
|
309
317
|
nestedArray.push(nestedObject);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reldens/storage",
|
|
3
3
|
"scope": "@reldens",
|
|
4
|
-
"version": "0.10.0-beta.
|
|
4
|
+
"version": "0.10.0-beta.34",
|
|
5
5
|
"description": "Reldens - Storage",
|
|
6
6
|
"author": "Damian A. Pastorini",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"url": "https://github.com/damian-pastorini/reldens-storage/issues"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@mikro-orm/core": "^5.0.
|
|
48
|
-
"@mikro-orm/mongodb": "^5.0.
|
|
47
|
+
"@mikro-orm/core": "^5.0.1",
|
|
48
|
+
"@mikro-orm/mongodb": "^5.0.1",
|
|
49
49
|
"@reldens/utils": "^0.10.0-beta.4",
|
|
50
50
|
"knex": "^1.0.3",
|
|
51
51
|
"mysql": "^2.18.1",
|