File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import { Model } from '../../../src/model';
22import User from './user' ;
33import { BelongsTo } from '../../../src/drivers/default/relations/belongsTo' ;
44import { DefaultPersistedAttributes } from '../../../src/types/defaultPersistedAttributes' ;
5+ import Tag from './tag' ;
6+ import { HasMany } from '../../../src/drivers/default/relations/hasMany' ;
57
68export 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}
Original file line number Diff line number Diff line change 11import { 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}
You can’t perform that action at this time.
0 commit comments