@smallprod/models
Version:
62 lines (55 loc) • 1.42 kB
text/typescript
import {
AllowNull,
AutoIncrement,
BigInt,
Date,
Entity,
FieldName,
Id,
ManyToMany,
NonPersistent,
PrimaryKey,
Table,
Unique,
Varchar,
} from '../../..';
import ArticleEntity from './article.entity';
export default class UserEntity extends Entity {
private id = -1; // This attribute is a primary key and is treated has the id for findById(), delete() and update()
private firstname: string;
private lastname: string;
private email: string;
private birthDate: Date;
private age: number; // This attribute is not persisted in the table
// The second parameter specifies if the ORM should always fetch articles or not
private articles: ArticleEntity[] = [];
public constructor(
firstname: string,
lastname: string,
email: string,
birthDate: Date,
) {
super();
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
this.birthDate = birthDate;
this.age = 0; // Imagine we compute the age from the birthDate
}
public addArticle = (article: ArticleEntity) => this.articles.push(article);
public getId = () => this.id;
public getArticles = () => this.articles;
}