vona-module-a-orm 5.0.44 → 5.0.46

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.
@@ -3,6 +3,7 @@ import type { BeanModelMeta } from '../bean/bean.model/bean.model_meta.ts';
3
3
  import type { TypeModelColumn, TypeModelColumns } from '../types/modelWhere.ts';
4
4
  import type { IModelClassRecord } from '../types/onion/model.ts';
5
5
  export declare function isRaw(raw: any): boolean;
6
+ export declare function isRef(ref: any): boolean;
6
7
  export declare function getTableOrTableAlias(table: string): string;
7
8
  export declare function getTargetColumnName(column: string): string;
8
9
  export declare function prepareColumns<TRecord>(columns?: TypeModelColumns<TRecord>): Array<TypeModelColumn<TRecord>> | undefined;
package/dist/index.js CHANGED
@@ -846,6 +846,9 @@ const OpValues = Object.values(Op);
846
846
  function isRaw(raw) {
847
847
  return typeof raw?.constructor === 'function' && raw?.constructor?.name === 'Raw';
848
848
  }
849
+ function isRef(ref) {
850
+ return typeof ref?.constructor === 'function' && ref?.constructor?.name === 'Ref';
851
+ }
849
852
  function getTableOrTableAlias(table) {
850
853
  const _table = table.toString();
851
854
  return _table.includes(' as ') ? _table.split(' as ')[1].trim() : _table;
@@ -985,7 +988,7 @@ function _buildWhereColumn(having, knex, builder, column, value, op) {
985
988
  return;
986
989
  }
987
990
  // raw
988
- if (isRaw(value)) {
991
+ if (isRaw(value) || isRef(value)) {
989
992
  _buildWhereColumnOpNormal(having, knex, builder, column, value, op ?? Op.eq);
990
993
  return;
991
994
  }
@@ -1948,6 +1951,9 @@ class BeanModelCrudInner extends BeanModelView {
1948
1951
  const dataTemp2 = this._prepareInsertDataByOptions(table, dataTemp, options);
1949
1952
  // then
1950
1953
  const [dataNew, dataNewOriginal] = await this.prepareData(table, dataTemp2);
1954
+ if (isNil(cast(dataNewOriginal).id) && Object.prototype.hasOwnProperty.call(dataNewOriginal, 'id')) {
1955
+ delete cast(dataNewOriginal).id;
1956
+ }
1951
1957
  datas.push(dataNew);
1952
1958
  datasOriginal.push(dataNewOriginal);
1953
1959
  }
@@ -2494,7 +2500,7 @@ let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
2494
2500
  for (let index = 0; index < entities.length; index++) {
2495
2501
  const entity = entities[index];
2496
2502
  if (entity[relationName]) {
2497
- // donot checkif has id of entity[relationName], for safety
2503
+ // donot check if has id of entity[relationName], for safety
2498
2504
  const item = await modelTarget.get({
2499
2505
  [key]: cast(entity).id
2500
2506
  });
@@ -2527,13 +2533,18 @@ let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
2527
2533
  if (entity[relationName] && entity[relationName].length > 0) {
2528
2534
  const entityId = cast(entity).id;
2529
2535
  const idsTo = entity[relationName].map(item => item.id).filter(id => !isNil(id));
2530
- const itemsTarget = await cast(modelTarget).__select_raw(undefined, {
2531
- where: {
2532
- [key]: entityId,
2533
- id: idsTo
2534
- }
2535
- }, methodOptionsReal);
2536
- const idsTarget = itemsTarget.map(item => item.id);
2536
+ let idsTarget;
2537
+ if (idsTo.length === 0) {
2538
+ idsTarget = [];
2539
+ } else {
2540
+ const itemsTarget = await cast(modelTarget).__select_raw(undefined, {
2541
+ where: {
2542
+ [key]: entityId,
2543
+ id: idsTo
2544
+ }
2545
+ }, methodOptionsReal);
2546
+ idsTarget = itemsTarget.map(item => item.id);
2547
+ }
2537
2548
  for (const child of entity[relationName]) {
2538
2549
  if (!isNil(child.id) && !idsTarget.includes(child.id)) {
2539
2550
  throw new Error(`invalid id: ${child.id}`);
@@ -4117,4 +4128,4 @@ const $relationMutate = {
4117
4128
  belongsToMany
4118
4129
  };
4119
4130
 
4120
- export { $Dto, $column, $columns, $columnsAll, $locale, $relation, $relationDynamic, $relationMutate, $tableColumns, $tableComments, $tableDefaults, $tableName, AopMethodTransaction, BeanDatabase, BeanDatabaseDialectBase, BeanModel, BeanModelBase, BeanModelMeta, BroadcastColumnsClear, BroadcastDatabaseClientReload, Database, DatabaseDialect, Entity, EntityBase, EntityBaseEmpty, EntityBaseInner, EntityBaseSimple, Errors, EventClientNameReal, EventColumnsClear, EventDatabaseClientReload, ExtendKnex, ExtendSchemaBuilder, ExtendTableBuilder, Main, Model, Op, OpAggrs, OpJoint, OpJointValues, OpNormal, OpNormalValues, OpValues, ScheduleSoftDeletionPrune, ScopeModuleAOrm, ServiceCacheEntity, ServiceCacheQuery, ServiceColumns, ServiceColumnsCache, ServiceDatabase, ServiceDatabaseAsyncLocalStorage, ServiceDatabaseClient, ServiceDb, ServiceEntityResolver, ServiceModelResolver, ServiceRelations, ServiceTransaction, ServiceTransactionAsyncLocalStorage, ServiceTransactionConsistency‌, ServiceTransactionFiber, ServiceTransactionState, SymbolKeyEntity, SymbolKeyEntityMeta, SymbolKeyFieldsMore, SymbolKeyModelOptions, TransactionIsolationLevelsMap, buildWhere, config, configDefault, getClassEntityFromClassModel, getTableOrTableAlias, getTargetColumnName, isAggrColumn, isRaw, locales, prepareClassModel, prepareColumns };
4131
+ export { $Dto, $column, $columns, $columnsAll, $locale, $relation, $relationDynamic, $relationMutate, $tableColumns, $tableComments, $tableDefaults, $tableName, AopMethodTransaction, BeanDatabase, BeanDatabaseDialectBase, BeanModel, BeanModelBase, BeanModelMeta, BroadcastColumnsClear, BroadcastDatabaseClientReload, Database, DatabaseDialect, Entity, EntityBase, EntityBaseEmpty, EntityBaseInner, EntityBaseSimple, Errors, EventClientNameReal, EventColumnsClear, EventDatabaseClientReload, ExtendKnex, ExtendSchemaBuilder, ExtendTableBuilder, Main, Model, Op, OpAggrs, OpJoint, OpJointValues, OpNormal, OpNormalValues, OpValues, ScheduleSoftDeletionPrune, ScopeModuleAOrm, ServiceCacheEntity, ServiceCacheQuery, ServiceColumns, ServiceColumnsCache, ServiceDatabase, ServiceDatabaseAsyncLocalStorage, ServiceDatabaseClient, ServiceDb, ServiceEntityResolver, ServiceModelResolver, ServiceRelations, ServiceTransaction, ServiceTransactionAsyncLocalStorage, ServiceTransactionConsistency‌, ServiceTransactionFiber, ServiceTransactionState, SymbolKeyEntity, SymbolKeyEntityMeta, SymbolKeyFieldsMore, SymbolKeyModelOptions, TransactionIsolationLevelsMap, buildWhere, config, configDefault, getClassEntityFromClassModel, getTableOrTableAlias, getTargetColumnName, isAggrColumn, isRaw, isRef, locales, prepareClassModel, prepareColumns };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-orm",
3
3
  "type": "module",
4
- "version": "5.0.44",
4
+ "version": "5.0.46",
5
5
  "title": "a-orm",
6
6
  "vonaModule": {
7
7
  "capabilities": {