fix(database): cannot read properties of null (reading 'constructor')

This commit is contained in:
chenos 2022-11-30 10:57:41 +08:00
parent 1764b53a9b
commit 7cfa939f63
3 changed files with 8 additions and 4 deletions

View File

@ -15,7 +15,7 @@ export async function get(ctx: Context, next) {
context: ctx,
});
ctx.body = instance;
ctx.body = instance || {};
await next();
}

View File

@ -1,10 +1,10 @@
import lodash, { omit } from 'lodash';
import lodash from 'lodash';
import { SingleAssociationAccessors, Transactionable } from 'sequelize';
import { Model } from '../model';
import { Appends, Except, Fields, Filter, TargetKey, UpdateOptions } from '../repository';
import { updateModelByValues } from '../update-associations';
import { RelationRepository, transaction } from './relation-repository';
import { handleAppendsQuery } from '../utils';
import { RelationRepository, transaction } from './relation-repository';
export interface SingleRelationFindOption extends Transactionable {
fields?: Fields;

View File

@ -1,6 +1,6 @@
import crypto from 'crypto';
import { Model } from './model';
import { IdentifierError } from './errors/identifier-error';
import { Model } from './model';
type HandleAppendsQueryOptions = {
templateModel: any;
@ -10,6 +10,10 @@ type HandleAppendsQueryOptions = {
export async function handleAppendsQuery(options: HandleAppendsQueryOptions) {
const { templateModel, queryPromises } = options;
if (!templateModel) {
return [];
}
const primaryKey = templateModel.constructor.primaryKeyAttribute;
const results = await Promise.all(queryPromises);