fix(cards): FK card_responses via relation JoinColumn + save(create)
Double mapping @Column/@JoinColumn sur id_card ; persist response via card/user relations. Garde update() sur l’instance (évite save parent qui nullifiait les FK enfants). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
RelationId,
|
||||
} from 'typeorm';
|
||||
import { CardInstance } from './card_instances.entity';
|
||||
import { Users } from './users.entity';
|
||||
@@ -20,20 +21,21 @@ export class CardResponse {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'id_card', type: 'uuid' })
|
||||
id_card: string;
|
||||
|
||||
/** FK carte — une seule source de vérité via @JoinColumn (pas de @Column doublon). */
|
||||
@ManyToOne(() => CardInstance, (c) => c.responses, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_card', referencedColumnName: 'id' })
|
||||
card: CardInstance;
|
||||
|
||||
@Column({ name: 'id_utilisateur', type: 'uuid' })
|
||||
id_utilisateur: string;
|
||||
@RelationId((r: CardResponse) => r.card)
|
||||
id_card: string;
|
||||
|
||||
@ManyToOne(() => Users, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
||||
user: Users;
|
||||
|
||||
@RelationId((r: CardResponse) => r.user)
|
||||
id_utilisateur: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: CardResponseActionType,
|
||||
|
||||
Reference in New Issue
Block a user