Skip to content

Instantly share code, notes, and snippets.

@taowen
Created July 23, 2019 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taowen/9e180205947a9e50036ae7a91f2440e0 to your computer and use it in GitHub Desktop.
Save taowen/9e180205947a9e50036ae7a91f2440e0 to your computer and use it in GitHub Desktop.
@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