I looked at other issues that throw the same error, but none of then worked for me. I tried rename, import, put in config file, I read the typeorm doc a thousand times but I can't find the solution. Can anyone help me?
On ormconfig.json:
"entities": [
"./src/models/*.ts"
],
Category entity:
import {
Column,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import Product from './Product';
import User from './User';
@Entity('categories')
class Category {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column('varchar')
name: string;
@Column('varchar')
description?: string;
@ManyToOne(() => User, categories => Category)
@JoinColumn()
user: User;
@OneToMany(() => Product, product => product.category)
products: Product[];
}
export default Category;
Product entity:
import { PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import Category from './Category';
import Model from './Model';
import Provider from './Provider';
import User from './User';
export enum Genre {
FEMALE = 'F',
MALE = 'M',
}
export enum Size {
PP = 'PP',
P = 'P',
M = 'M',
G = 'G',
GG = 'GG',
SIZE_33 = '33',
SIZE_34 = '34',
SIZE_35 = '35',
SIZE_36 = '36',
SIZE_37 = '37',
SIZE_38 = '38',
SIZE_39 = '39',
SIZE_40 = '40',
SIZE_41 = '41',
SIZE_42 = '42',
SIZE_43 = '43',
SIZE_44 = '44',
SIZE_45 = '45',
SIZE_46 = '46',
SIZE_47 = '47',
SIZE_48 = '48',
SIZE_49 = '49',
SIZE_50 = '50',
SIZE_51 = '51',
SIZE_52 = '52',
}
export enum Status {
IN_STOCK = 'I',
OUTPUT = 'O',
}
enum Purchase_type {
CONSIGNED = 'C',
OWNER = 'O',
}
class Product {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column('varchar')
name: string;
@Column('enum')
genre: Genre;
@Column('varchar')
color: string;
@Column('enum')
size: Size;
@Column('enum')
status: Status;
@Column('datetime')
created_at: Date;
@Column('varchar')
id_photo?: string;
@Column('varchar')
obs?: string;
@Column('float')
sale_value: number;
@Column('float')
purchase_value: number;
@Column('enum')
purchase_type: Purchase_type;
@Column('varchar')
brand: string;
@ManyToOne(() => User, user => user.products)
@JoinColumn()
user: User;
@ManyToOne(() => Provider, provider => provider.products)
@JoinColumn()
provider: Provider;
@ManyToOne(() => Category, category => category.products)
category: Category;
@ManyToOne(() => Model, model => model.products)
@JoinColumn()
model: Model;
}
export default Product;
The error:
(node:10691) UnhandledPromiseRejectionWarning: Error: Entity metadata for Category#products was not found. Check if you specified a correct entity object and if it's connected in the connection options.
at /home/guilherme/Documentos/Restore/src/metadata-builder/EntityMetadataBuilder.ts:664:23
at Array.forEach ()
at EntityMetadataBuilder.computeInverseProperties (/home/guilherme/Documentos/Restore/src/metadata-builder/EntityMetadataBuilder.ts:659:34)
at /home/guilherme/Documentos/Restore/src/metadata-builder/EntityMetadataBuilder.ts:118:56
at Array.forEach ()
at EntityMetadataBuilder.build (/home/guilherme/Documentos/Restore/src/metadata-builder/EntityMetadataBuilder.ts:118:25)
at ConnectionMetadataBuilder.buildEntityMetadatas (/home/guilherme/Documentos/Restore/src/connection/ConnectionMetadataBuilder.ts:66:111)
at Connection.buildMetadatas (/home/guilherme/Documentos/Restore/src/connection/Connection.ts:517:59)
at Connection. (/home/guilherme/Documentos/Restore/src/connection/Connection.ts:193:18)
at step (/home/guilherme/Documentos/Restore/node_modules/tslib/tslib.js:141:27)