Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation fixtures #165

Open
mickeiik opened this issue Feb 12, 2021 · 0 comments
Open

Relation fixtures #165

mickeiik opened this issue Feb 12, 2021 · 0 comments
Assignees

Comments

@mickeiik
Copy link

Firstly, thank you for the work on this library.

I am running into an issue similar to class-transformer decorators are ignored #87 in some way.

My setup is the following.

I am using special columns of typeorm like this in an entity I will call 'meeting'

@Entity( 'meeting' )
export class MeetingEntity {
  @PrimaryColumn( { type: 'uuid' } )
  meetingId!: string;

  @CreateDateColumn( {
    type: 'timestamp without time zone',
    transformer: { from: LocalDateTimeTransformer.from, to: () => undefined },
  } )
  createdAt!: LocalDateTime; // From js-joda
}

I have another entity in relation with 'meeting' that I will call 'person' :

@Entity( 'person' )
export class PersonEntity {
  @PrimaryColumn( { type: 'uuid' } )
  personId!: string;

  @ManyToOne( () => MeetingEntity, { eager: true } )
  @JoinColumn( { name: 'meetingId' } )
  meeting?: MeetingEntity;
  @Column()
  @RelationId( ( meeting: MeetingEntity ) => meeting.meeting )
  meetingId!: string;
}

In my 'meeting.yml' file :

entity: person
items:
  person{1..1000}:
    personId: '{{random.uuid}}'
    meetingId: '@meeting*'

The 'issue' is the following. When 'building' the relation meetingId: '@meeting*' the library retrieves from the database the full random meeting which contains the 'createdAt' field with of value of type 'LocalDateTime' created by the column 'LocalDateTimeTransformer'.
This field is then passed to 'class-transformer' who tries to instantiate the field (new LocalDate( LocalDate ) ) which obviously fails.

For now my fix consists of deleting all the LocalDate fields from the entity relation in 'preProcess()'.

My proposition would be not to load the full entity into the relation but instead only set the id of the target entity.
When the entity is saved typeorm is ignoring the data anyways and saves the id in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants