typeorm: ManyToOne eager query error
Issue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[x] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
I have the following entities:
PostComment
@Entity()
export class PostComment {
@PrimaryGeneratedColumn()
id: number;
@Column({ default: true })
active: boolean;
@Column({
type: String,
nullable: true,
})
authorName?: String;
@Column({
type: String,
nullable: true,
})
comment?: String;
@ManyToOne(_ => Post, post => post.comments, {eager: true})
@JoinColumn()
post: Post;
}
Post
@Entity()
export class Post {
@PrimaryGeneratedColumn()
id: number;
@Column({ default: true })
active: boolean;
@Column()
title: string;
@Column()
text: string;
@OneToMany(_ => PostComment, comment => comment.post, {
cascade: true,
})
comments: PostComment[];
}
When try to find all PostComment with an post id:
repository.find({ post: { id: 1 } })
it gives the following error: table name "PostComment_post" specified more than once.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 17 (6 by maintainers)
Commits related to this issue
- bumping typeorm version to resolve https://github.com/typeorm/typeorm/issues/2661 — committed to breytex/todotimer by breytex 5 years ago
Still experiencing this bug, as described above, with TypeORM version
0.2.18.Can the issue be re-opened for examination?
@sgarner I’ve solved similar bug with custom naming strategy
I confirm the error in version 0.2.16
Some observations:
2.1 Without eager
2.1 Without custom field name. In this case in table name is currencyId
2.2 With field name other than currency_id in my case
After some digging, I realized this error is due to Typeorm creating some kind of variable when using
eagerloading that is longer than Postgres limit for names.For example, if you are
eagerloadingproductswithcustomer, typeorm will create something along the lines ofcustomer_products, connecting the two. If that name is longer than 63 bytes (Postgres limit) the query will crash.I’m not 100% sure about how everything works under the hood but this is the summary of it I think.
Also experiencing this, 0.2.25
Experiencing the same issue on
@OneToManyVersion: 0.2.25
Also experiencing this, 0.2.25
I’ve encountered same errors. It was said to be fixed in 0.2.14, but my TypeORM is in 0.2.16.