Skip to content

Commit ed3cea6

Browse files
committed
Added missing relations in test models
1 parent 9df9349 commit ed3cea6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tests/stubs/models/post.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Model } from '../../../src/model';
22
import User from './user';
33
import { BelongsTo } from '../../../src/drivers/default/relations/belongsTo';
44
import { DefaultPersistedAttributes } from '../../../src/types/defaultPersistedAttributes';
5+
import Tag from './tag';
6+
import { HasMany } from '../../../src/drivers/default/relations/hasMany';
57

68
export default class Post extends Model<
79
{
@@ -10,6 +12,7 @@ export default class Post extends Model<
1012
DefaultPersistedAttributes,
1113
{
1214
user: User;
15+
tags?: Tag[];
1316
}
1417
> {
1518
$resource(): string {
@@ -19,4 +22,9 @@ export default class Post extends Model<
1922
public user(): BelongsTo<User> {
2023
return new BelongsTo(User, this);
2124
}
25+
26+
public tags(): HasMany<Tag> {
27+
return new HasMany(Tag, this);
28+
}
29+
2230
}

tests/stubs/models/user.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import { Model } from '../../../src/model';
2+
import Post from './post';
3+
import { HasMany } from '../../../src/drivers/default/relations/hasMany';
4+
import { DefaultPersistedAttributes } from '../../../lib/types/defaultPersistedAttributes';
25

3-
export default class User extends Model<{
6+
export type UserAttributes = {
47
name: string;
5-
}> {
8+
}
9+
10+
export type UserRelations = {
11+
posts: Post[];
12+
}
13+
export default class User extends Model<UserAttributes, DefaultPersistedAttributes, UserRelations> {
614
$resource(): string {
715
return 'users';
816
}
17+
18+
public posts(): HasMany<Post> {
19+
return new HasMany(Post, this);
20+
}
921
}

0 commit comments

Comments
 (0)