@reldens/storage 0.10.0-beta.34 → 0.10.0-beta.38

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.
@@ -162,7 +162,7 @@ class BaseDriver
162
162
  Logger.error('Custom query method not found in raw model.', methodName, this.rawModel);
163
163
  return false;
164
164
  }
165
- return this.rawModel[methodName](methodOptions);
165
+ return this.rawModel[methodName](methodOptions, this);
166
166
  }
167
167
 
168
168
  }
@@ -132,7 +132,7 @@ class MikroOrmDriver extends BaseDriver
132
132
 
133
133
  async loadAllWithRelations(relations)
134
134
  {
135
- let entities = await this.repository.find(filter, this.queryBuilder(true, true, true));
135
+ let entities = await this.loadAll();
136
136
  return await this.appendRelationsToCollection(entities, relations);
137
137
  }
138
138
 
@@ -232,11 +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;
235
+ if(typeof this.rawModel.entity.relationMappings !== 'function'){
236
+ return entitiesCollection;
237
237
  }
238
238
  if(!sc.isArray(relations) || 0 === relations.length){
239
- relations = Object.keys(this.rawModel.entity.relationsMappings() || {});
239
+ relations = Object.keys(this.rawModel.entity.relationMappings() || {});
240
240
  }
241
241
  if(0 === relations.length){
242
242
  return entitiesCollection;
@@ -250,12 +250,12 @@ class MikroOrmDriver extends BaseDriver
250
250
  async appendRelatedEntities(entity, relations)
251
251
  {
252
252
  // @TODO - BETA - Refactor and improve.
253
- if(typeof this.rawModel.entity.relationsMappings !== 'function'){
254
- return false;
253
+ if(typeof this.rawModel.entity.relationMappings !== 'function'){
254
+ return entity;
255
255
  }
256
- let relationsMappings = typeof this.rawModel.entity.relationsMappings();
256
+ let relationMappings = this.rawModel.entity.relationMappings();
257
257
  for(let i of relations){
258
- let relation = relationsMappings[i];
258
+ let relation = relationMappings[i];
259
259
  let relationRepository = this.server.getEntity(relation.entityName);
260
260
  let isManyToOne = 'm:1' === relation.reference;
261
261
  let isOneToMany = '1:m' === relation.reference;
@@ -266,17 +266,18 @@ class MikroOrmDriver extends BaseDriver
266
266
  entity[i] = await relationRepository.loadBy(relation.join.to, entity[relation.join.from]);
267
267
  }
268
268
  }
269
+ return entity;
269
270
  }
270
271
 
271
272
  async createNested(newInstance, params)
272
273
  {
273
- if(typeof this.rawModel.entity.relationsMappings !== 'function'){
274
+ if(typeof this.rawModel.entity.relationMappings !== 'function'){
274
275
  return false;
275
276
  }
276
- let relationsMappings = this.rawModel.entity.relationsMappings();
277
- for(let i of Object.keys(relationsMappings)){
277
+ let relationMappings = this.rawModel.entity.relationMappings();
278
+ for(let i of Object.keys(relationMappings)){
278
279
  // @TODO - BETA - Refactor and improve.
279
- let relationData = relationsMappings[i];
280
+ let relationData = relationMappings[i];
280
281
  let relationEntity = this.server.entityManager.get(relationData.entityName).rawModel.entity;
281
282
  if(!relationEntity){
282
283
  Logger.warning('Factory not found for relation definition:', relationData);
@@ -300,7 +301,7 @@ class MikroOrmDriver extends BaseDriver
300
301
  async createOne(params, i, relationEntity, newInstance, relationData)
301
302
  {
302
303
  params[i] = newInstance[relationData.join.from];
303
- let nestedObject = relationEntity.create(params[i]);
304
+ let nestedObject = relationEntity.createByProps(params[i]);
304
305
  await this.repository.persist(nestedObject).flush();
305
306
  await this.orm.em.flush();
306
307
  newInstance[i] = nestedObject;
@@ -311,7 +312,7 @@ class MikroOrmDriver extends BaseDriver
311
312
  let nestedArray = [];
312
313
  for(let objectData of params[i]){
313
314
  objectData[relationData.join.to] = newInstance[relationData.join.from];
314
- let nestedObject = relationEntity.create(objectData);
315
+ let nestedObject = relationEntity.createByProps(objectData);
315
316
  await this.repository.persist(nestedObject).flush();
316
317
  await this.orm.em.flush();
317
318
  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.34",
4
+ "version": "0.10.0-beta.38",
5
5
  "description": "Reldens - Storage",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",