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

fix: wrap nested property names #3813

Closed
wants to merge 1 commit into from
Closed

fix: wrap nested property names #3813

wants to merge 1 commit into from

Conversation

epechuzal
Copy link
Contributor

@epechuzal epechuzal commented Dec 2, 2022

We have entities with relations using property names in kebab case, like

export class ParentEntity {
  @PrimaryKey()
  id: number;

  @ApiProperty()
  @OneToOne({ entity: () => SomeOtherEntity, nullable: true, mappedBy: 'parent' })
  'kebab-case-property': SomeOtherEntity;
}

When I use an entity factory the hydrator generates code like

if (entity.parent && !entity.parent.kebab-case-property) {
        entity.parent.kebab-case-property = entity;
      }

Which leads to an error because the above code is not valid JS.

This would be fine if only entity.parent.kebab-case-property was formatted like entity.parent['kebab-case-property'].

I noticed we have the this.wrap() method which does this manipulation for us for other properties, but we are not using it in this particular part of the code.

This PR will just add that in so that all properties are "fixed".

@B4nan
Copy link
Member

B4nan commented Dec 3, 2022

The change is apparently wrong as it breaks existing tests. You should at least adjust the existing tests so they fail without your change, or introduce new test for it in the same manner.

@epechuzal
Copy link
Contributor Author

The change is apparently wrong as it breaks existing tests. You should at least adjust the existing tests so they fail without your change, or introduce new test for it in the same manner.

The PR here is basically the quick change I made to my local project so that I could use the entity factory, which I was hoping that it would be a low impact fix.

To be honest I don't fully understand exactly how the hydrator works so it is very possible that I broke core functionality with this change - I will take another look but I am not very confident I will figure it out :)

@B4nan B4nan closed this in 22350bd Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants