import { column, relation } from "@alpha.consultings/eloquent-orm.js";
import { MongoModel } from "@alpha.consultings/eloquent-orm.js/Model";
type CommentAttrs = {
id?: number;
body?: string;
commentable_type?: string;
commentable_id?: number;
};
type PhotoAttrs = {
id?: number;
path?: string;
commentable_id?: number;
commentable_type?: string;
};
export class Comment extends MongoModel<CommentAttrs> {
static tableName = "comments";
static connectionName = "mongo";
static schema = {
id: column("increments", undefined, { primary: true }),
body: column("string", 255),
commentable_id: column("string"),
commentable_type: column("string", 255),
commentable: relation("morphTo", "Image", { morphName: "commentable" }),
};
constructor() {
super("comments", "mongo");
}
}
export class Photo extends MongoModel<PhotoAttrs> {
static tableName = "photos";
static connectionName = "mongo";
static schema = {
id: column("increments", undefined, { primary: true }),
path: column("string", 255),
imageable_id: column("string"),
imageable_type: column("string", 255),
imageable: relation("morphTo", "GeoLocation", { morphName: "imageable" }),
comments: relation("morphMany", "Comment", { morphName: "commentable" }),
};
constructor() {
super("photos", "mongo");
}
}