TypeOrm 外键实体出现的一个错误
Error: Entity metadata for User#comments was not found. Check if you specified a correct entity object and if it's connected in the connection options.
我们在外键表引入的时候出现这个异常,原引入关联的方式如下
import { Comment, UserMeta } from '..';
@OneToMany(type => UserMeta, userMeta => userMeta.user, {
cascade: true,
eager: true,
})
metas?: UserMeta[];
@OneToMany(type => Comment, c => c.author, {
cascade: true,
eager: true,
})
comments?: Comment[];
发现只有 UserMeta这个表可以关联成功,而 Comment 却不可以,后将 Comment 的引入改为
import { UserMeta } from '..';
import { DeepPartial } from '../../common/shared-types';
import { BaseEntity } from '../base.entity';
import { Comment } from '../comments/comment.entity';
编译通过。查阅相关资料应该是相路径引入的问题
网友评论