TypeORMError 발생
349
작성한 질문수 13
import { Exclude, Expose } from "class-transformer";
import {
BeforeInsert,
Column,
Entity,
Index,
JoinColumn,
ManyToOne,
OneToMany,
} from "typeorm";
import { makeId, slugify } from "../utils/helpers";
import Comment from "./Comment";
import BaseEntity from "./BaseEntity";
import Sub from "./Sub";
import { User } from "./User";
import Vote from "./Vote";
@Entity("posts")
export default class Post extends BaseEntity {
@Index()
@Column()
identifier: string;
@Column()
title: string;
@Index()
@Column()
slug: string;
@Column({ nullable: true, type: "text" })
body: string;
@Column()
subName: string;
@Column()
username: string;
@ManyToOne(() => User, (user) => user.posts)
@JoinColumn({ name: "username", referencedColumnName: "username" })
user: User;
@ManyToOne(() => Sub, (sub) => sub.posts)
@JoinColumn({ name: "subName", referencedColumnName: "name" })
sub: Sub;
@Exclude()
@OneToMany(() => Comment, (comment) => comment.post)
comments: Comment[];
@Exclude()
@OneToMany(() => Vote, (vote) => vote.post)
votes: Vote[];
@Expose() get url(): string {
return `/r/${this.subName}/${this.identifier}/${this.slug}`;
}
@Expose() get commentCount(): number {
return this.comments?.length;
}
@Expose() get voteScore(): number {
return this.votes?.reduce((memo, curt) => memo + (curt.value || 0), 0);
}
protected userVote: number;
setUserVote(user: User) {
const index = this.votes?.findIndex((v) => v.username === user.username);
this.userVote = index > -1 ? this.votes[index].value : 0;
}
@BeforeInsert()
makeIdAndSlug() {
this.identifier = makeId(7);
this.slug = slugify(this.title);
}
}
위와 같은 오류가 뜨는데 어떻게 해결해야 하나요
답변 1
0
안녕하세요!!
import { User } from "./User";
여기가 의심되는데 여기 어떤 식으로 export 되어있는지 봐주시고
만약 default로 User가 export 되어 있다면
import User from "./User"; 로 바꿔주세요 ~
감사합니다.
toJson을 추가하면 [sub].tsx에서 sub를 받아오지 못합니다.
0
118
2
쿠키 저장이 되지 않습니다.
0
224
1
AxiosError {message: 'Request failed with status code 401/500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', (2)
0
580
1
AxiosError {message: 'Request failed with status code 401/500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE',
0
649
1
overload 에러
0
170
1
docker compose up 오류
0
207
1
부록) remark 강의 중 parmas 오류
0
139
1
3000번은 잘 들어가지는데 80번은 안됩니다.
1
295
0
커뮤니티를 올리고 난 후 404 page
0
209
1
tailwind css 문제인지, className 에 적용한 css가 적용되지 않아요.
0
1042
2
tsx 수정 시 마다 빌드 후 서버 시작 해야하나요?
0
652
2
useState 쳤을 때 자동완성 되는 단축키 무엇인가요? extention 인가요?
0
805
2
리액트 서버 npm run dev 와 npm run build 후 npm start 의 차이
0
4602
2
data 폴더가 생성되지 않아요.
0
525
1
docker-compose up 오류
0
814
1
회원 가입 페이지 기능 생성(3) 중 에러
0
380
2
Entity에 toJSON 코드 입력 후 404 에러
0
252
1
context에서 useEffect 선언 부분 질문 있어요.
0
295
1
src 폴더구조
0
511
2
서버 실행 시 에러 관련하여 답변받고 1차 조치했는데 여전하여서 질문 남깁니다
0
298
1
엔티티 모두 작성 후 서버 실행 시 에러가 발생합니다
0
313
1
회원가입 누르면 404에러가 뜹니다 ;-;
1
424
1
nextjs버젼에 대해서 질문드립니다.
0
373
1
<npm run dev>시 -61 에러가 나타납니다!
0
357
1





