@smallprod/models
Version:
66 lines (55 loc) • 1.28 kB
text/typescript
import {
AutoCreateNUpdate,
AutoIncrement,
BigInt,
Date,
Entity,
EntityManager,
Id,
ManyToMany,
ManyToOne,
PrimaryKey,
Table,
Varchar,
} from '@smallprod/models';
import CategoryEntity from './category.entity';
import UserEntity from './user.entity';
import { Field } from '@smallprod/models/migration/types/createtable';
export default class ArticleEntity extends Entity {
private id = 0;
private title: string;
private publishedAt: Date;
private authors: UserEntity[] = [];
private category: CategoryEntity | null = null;
constructor(title: string, publishedAt: Date, category: CategoryEntity) {
super();
this.title = title;
this.publishedAt = publishedAt;
this.category = category;
}
public fetchAuthors = async () => {
return await this.fetch('authors');
};
public fetchCategory = async () => {
return await this.fetch('category');
};
}
EntityManager.registerEntity(ArticleEntity);