For some unknown reason this.toEntities
return my object to undefined
I dig few more and found out that return new this.entityClass(model.toObject())
return all data to undefined
. Please have a look at the console area.
im running loobpack with this command line
lb-tsc --copy-resources && tsc-watch --target ESNext --outDir ./dist --onSuccess "node --inspect ."
this is my packages version
macOS: Sonoma 14.1
node: 16.20.2
➜ pnpm list
Legend: production dependency, optional only, dev only
[email protected] /Users/haziq.jasni/work/cgss-be
dependencies:
@loopback/authentication 10.1.1 @loopback/rest-explorer 6.1.1 bcrypt 5.1.0 jsonwebtoken 9.0.0
@loopback/authorization 0.14.1 @loopback/security 0.10.3 casbin 5.19.1 lodash 4.17.21
@loopback/boot 6.1.1 @loopback/service-proxy 6.1.1 check-password-strength 2.0.7 loopback-connector-mysql 6.1.0
@loopback/core 5.1.1 @types/bcrypt 5.0.0 date-fns 2.30.0 nodemailer 6.9.0
@loopback/repository 6.1.1 @types/jsonwebtoken 9.0.1 debug 4.3.4 tsconfig-paths 4.1.2
@loopback/rest 13.1.1 @types/nodemailer 6.4.7 email-validator 2.0.4 tslib 2.0.0
devDependencies:
@loopback/build 10.1.1 @types/lodash 4.14.197 eslint 8.53.0 tsc-watch 6.0.4
@loopback/eslint-config 14.0.2 @types/mocha 10.0.1 pm2 5.3.0 typescript 5.1.6
@loopback/testlab 6.1.1 @types/node 16.18.61 source-map-support 0.5.21
@types/debug 4.1.8 dotenv 16.0.3 tsc-alias 1.8.2
I ran few more test like below
console.log(
await this.emissionRepository.count(),
await this.emissionRepository.find(),
await this.plantActualDetailRepository.execute(`SELECT * FROM User`)
)
So if my understanding correctly my model is the one that doesn't really work well?. Since vanilla sql works perfectly.
import { Entity, model, property } from '@loopback/repository'
@model()
export class Emission extends Entity {
@property({
type: 'number',
id: true,
generated: true,
})
id?: number
@property({ type: 'number' })
no_of_year: number
@property({ type: 'number' })
co2_actual_emission: number
@property({ type: 'number' })
emissionId?: number
constructor(data?: Partial<Emission>) {
super(data)
}
}
export interface EmissionRelations {
// describe navigational properties here
}
export type EmissionWithRelations = Emission & EmissionRelations
Just found the answer by changing to this command lind (--target 2021)
And i can confirm that using es2022 will result in undefined model as stated above