Skip to content

Commit 7896bd7

Browse files
committed
fix: test
1 parent 484ec18 commit 7896bd7

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

packages/leoric/src/configuration.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {
22
APPLICATION_KEY,
3+
ApplicationContext,
34
Configuration,
45
IMidwayContainer,
56
Init,
67
Inject,
78
MidwayDecoratorService,
89
REQUEST_OBJ_CTX_KEY,
10+
ScopeEnum,
911
} from '@midwayjs/core';
1012
import { LeoricDataSourceManager } from './dataSourceManager';
1113
import { DATA_SOURCE_KEY, MODEL_KEY } from './decorator';
@@ -30,6 +32,9 @@ export class LeoricConfiguration {
3032
@Inject()
3133
decoratorService: MidwayDecoratorService;
3234

35+
@ApplicationContext()
36+
applicationContext: IMidwayContainer;
37+
3338
dataSourceManager: LeoricDataSourceManager;
3439

3540
@Init()
@@ -47,9 +52,9 @@ export class LeoricConfiguration {
4752
this.dataSourceManager.getDefaultDataSourceName()
4853
);
4954
const model = dataSource.models[getModelName(meta.modelName)];
50-
const ctx = instance[REQUEST_OBJ_CTX_KEY];
5155
const app = instance[APPLICATION_KEY];
52-
if (ctx) {
56+
if (this.applicationContext.getInstanceScope(instance) === ScopeEnum.Request) {
57+
const ctx = instance[REQUEST_OBJ_CTX_KEY];
5358
return class extends model {
5459
static get ctx() {
5560
return ctx;

packages/leoric/test/fixtures/multi/src/subsystem/controller/post.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export class PostController {
88

99
@Get('')
1010
async get() {
11-
return await this.postService.get();
11+
const data = await this.postService.get();
12+
console.log(data);
13+
return data;
1214
}
1315
}

packages/leoric/test/fixtures/multi/src/subsystem/model/post.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export default class Post extends Bone {
1010
@Column(DataTypes.TEXT)
1111
content: string;
1212

13-
@Column()
13+
@Column({name: 'created_at'})
1414
createdAt: Date;
1515

16-
@Column()
16+
@Column({name: 'updated_at'})
1717
updatedAt: Date;
1818
}

0 commit comments

Comments
 (0)