import { Field, ObjectType } from 'type-graphql';
import { Column, Entity, OneToMany, Unique } from 'typeorm';
import { TimeFrame } from '..';
import Base from '../Base';
@ObjectType()
@Entity({ name: 'sports' })
export default class Sport extends Base {
@Column({ type: 'text' })
label: string;
@Field(() => [TimeFrame])
@OneToMany(() => TimeFrame, (timeFrame) => timeFrame.sport, { lazy: true })
timeFrames: TimeFrame[];
}
TimeFrame.ts
import { Field, ObjectType } from 'type-graphql';
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany } from 'typeorm';
import { Sport } from '..';
import Base from '../Base';
@ObjectType()
@Entity({ name: 'time_frames' })
export default class TimeFrame extends Base {
@Column({ type: 'text' })
label: string;
@Field(() => Sport)
@ManyToOne(() => Sport, (sport) => sport.timeFrames, { lazy: true })
sport: Sport;
@Column({ nullable: false })
sportId: string;
}
In my timeFrame fixture, I need to access sportId and not just sport. To solve, I want to implement a preprocessor to set the ID based on the sport relation.
With programmatic setup, if I add a preprocessor it just hangs while building the entity.
Context: I have a relation like so:
Sport.ts
TimeFrame.ts
In my timeFrame fixture, I need to access
sportId
and not justsport
. To solve, I want to implement a preprocessor to set the ID based on thesport
relation. With programmatic setup, if I add a preprocessor it just hangs while building the entity.loadFixtures.ts
timeFrames.yml
TimeFrameProcessor.ts
It's logging
before build
but notafter build
. If I remove thepreProcess
method it resolves it. Thanks!Your Environment