Problem with Model table name #1601
-
Hi, I am trying to create a model named When I try to query the database with any model that extends app/Models/BaseIdModel.tsimport { DateTime } from 'luxon';
import { BaseModel, beforeSave, column } from '@ioc:Adonis/Lucid/Orm';
import Utils from 'App/Utils/Utils';
export default class BaseIdModel extends BaseModel {
@column({ isPrimary: true })
public id: number;
@column.dateTime({ autoCreate: true })
public createdAt: DateTime;
@column.dateTime({ autoCreate: true, autoUpdate: true })
public updatedAt: DateTime;
@beforeSave()
public static async generateId(model: BaseIdModel): Promise<void> {
model.id = Utils.uniqueId();
}
} app/Models/Offer.tsimport { column } from '@ioc:Adonis/Lucid/Orm';
import BaseIdModel from './BaseIdModel';
export default class Offer extends BaseIdModel {
@column()
public name: string;
@column()
public active: boolean;
} Whenever I call Offer.create({name: 'Offer1'}); the query that gets generated is: insert into "base_id_models" ("created_at", "id", "name", "updated_at") values ($1, $2, $3, $4) with error relation "base_id_models" does not exist Kindly help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yeah, the inhertance story with models is not that great. Something we will fix in the next release. For now you will have to explicitly define the table name on the models. import { column } from '@ioc:Adonis/Lucid/Orm';
import BaseIdModel from './BaseIdModel';
export default class Offer extends BaseIdModel {
public static table = 'offers'
} |
Beta Was this translation helpful? Give feedback.
Yeah, the inhertance story with models is not that great. Something we will fix in the next release. For now you will have to explicitly define the table name on the models.