Created
July 23, 2019 13:09
-
-
Save taowen/9e180205947a9e50036ae7a91f2440e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@sources.Mysql() | |
export class User extends Entity { | |
public id: number; | |
public name: string; | |
public inviterId: number; | |
public get inviter(): User { | |
return this.scene.load(User, { id: this.inviterId }); | |
} | |
public get posts() { | |
return this.scene.query(Post, { authorId: this.id }); | |
} | |
} | |
@sources.Mysql() | |
export class Post extends Entity { | |
public id: number; | |
public title: string; | |
public authorId: number; | |
public get author(): User { | |
return this.scene.load(User, { id: this.authorId }); | |
} | |
public get editor(): User { | |
return this.scene.load(User, { id: this.editorId }); | |
} | |
public get authorName(): string { | |
return this.author.name; | |
} | |
public get inviterName(): string { | |
const inviter = this.author.inviter; | |
return inviter ? inviter.name : 'N/A'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment