Closed ms1sistemas closed 1 year ago
18.3.0
16.3.1
import { DateTime } from "luxon"; import { BaseModel, HasOne, ModelQueryBuilderContract, beforeCreate, beforeFetch, beforeFind, column, hasOne, } from "@ioc:Adonis/Lucid/Orm"; import { v4 as uuidv4 } from "uuid"; import City from "./City"; export default class Supplier extends BaseModel { public static table = "people"; @column({ isPrimary: true }) public id: string; @column() public name: string; @column.dateTime({ autoCreate: true }) public createdAt: DateTime; @column.dateTime({ autoCreate: true, autoUpdate: true }) public updatedAt: DateTime; @hasOne(() => City, { localKey: "city_id", foreignKey: "id", }) public city: HasOne<typeof City>;
public async index({ request, auth }: HttpContextContract) { const { page, limit, order, type, search } = request.qs(); try { const suppliers = Supplier.query() .select( "id", "name", ) .preload("city", (query) => query.select("description")) return await suppliers } catch (error) { throw new RecordNotFoundException(error); }
RecordNotFoundException: Exception: Cannot preload "city", value of "Supplier.city_id" is undefined preload don't use de table name on the supplier model
Package version
18.3.0
Node.js and npm version
16.3.1
Sample Code (to reproduce the issue)
Controller Suppliers
Error