Issue with delete Entity that has ManyToMany relation
See original GitHub issueI have been banging my head against a wall this evening, and I can’t tell if I have done something wrong here. Standard entity, very simple for the most part. Postgres is the database.
@Entity('group')
export class Group {
@PrimaryGeneratedColumn({ name: 'id' })
id: number;
@Column({ name: 'name' })
name: string;
@Column({ name: 'owner_id' })
ownerId: number;
@Column({ name: 'created_by_id' })
createdById: number;
@ManyToOne(() => User)
@JoinColumn({ name: 'owner_id', referencedColumnName: 'id' })
owner: User;
@ManyToOne(() => User)
@JoinColumn({ name: 'created_by_id', referencedColumnName: 'id' })
createdBy: User;
@ManyToMany(() => Package, {
onDelete: 'CASCADE'
})
@JoinTable({
name: 'package_group_xref',
joinColumn: { name: 'group_id' },
inverseJoinColumn: { name: 'package_id' }
})
packages: Package[];
@ManyToMany(() => Document)
@JoinTable({
name: 'document_group_xref',
joinColumn: { name: 'group_id' },
inverseJoinColumn: { name: 'document_id' }
})
documents: Document[];
}
@Crud({ model: { type: Group } })
@ApiTags('groups')
@ApiBearerAuth()
@Controller('groups')
export class GroupController extends CrudControllerBase<Group> {
constructor(readonly service: GroupService) {
super(service);
}
}
A query is being generated that has identifiers in it that aren’t quoted. I am not even sure where group_documents_rid
is coming from–I assume it is a name generated by typeorm, maybe?
I have tried the delete on both sides of the relation, and I just get the inverse of the same error. One is document_groups_rid
, and this one, group_documents_rid
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
How to remove entity with ManyToMany relationship in JPA ...
Problem is that when I call EntityManager.remove() on some Group, JPA provider (in my case Hibernate) does not remove rows from join table...
Read more >Issue with delete Entity that has ManyToMany relation that is ...
I am having an issue with a TypeORM generated query dealing with a ManyToMany relationship between my Documents and Groups. The issue seems...
Read more >Hibernate Tips: The best way to remove entities from a many ...
Solution: · 1. Use a Set instead of a List · 2. Don't use CascadeType.REMOVE · 3. Provide utility methods for bidirectional associations...
Read more >Many-to-many relations - typeorm - GitBook
Many-to-many is a relation where A contains multiple instances of B, and B contain multiple ... This will only remove the record in...
Read more >Still having problems with using Remove on many-to ... - MSDN
I need a fix that deals with both the "Remove" and "Add" issues, and is specific to a many-to-many entity relationship.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@zMotivat0r Could you triage this issue and let me know if you think it is a nestjsx/crud or TypeORM issue?
Also, if you have an idea about what needs to be done, please let me know and I can try and make the changes if you don’t have the time.
@zMotivat0r There has been some more findings that I have posted over at the TypeORM issue tracker.
https://github.com/typeorm/typeorm/issues/6138
Basically, I have a workaround for the time being. I am not sure how stable it is, and that another issue won’t just pop up, but it seems that I need to name the property to the name of the column. There is a mismatch within TypeORM, where suddenly it wants to use the property name to find the column, which doesn’t find anything.