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

How to use it with nullable self-referential relations? #64

Closed
gbirke opened this issue Sep 16, 2019 · 2 comments
Closed

How to use it with nullable self-referential relations? #64

gbirke opened this issue Sep 16, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@gbirke
Copy link

gbirke commented Sep 16, 2019

I have a category entity set up like in the example that optionally points to another category, creating a parent/child relationship. The topmost categories don't have a parent (so its parent attribute is nullable)

My fixture looks like this:

entity: Category
items:
  category1:
    name: 'first'
    parent: null
    sortId: 1

I get an error when it tries to insert the fixture, because it tries to insert a second, empty category.

I've traced through the code to see what it's doing and it converts the {parent:null} from the fixture to an empty object {parent: {}} in the Entity.

@RobinCK RobinCK added the bug Something isn't working label Sep 17, 2019
@RobinCK
Copy link
Owner

RobinCK commented Sep 17, 2019

Maybe this is a bug
I use the following structure https://github.com/RobinCK/typeorm-fixtures-sample/blob/master/fixtures/Category.yml

@gbirke
Copy link
Author

gbirke commented Sep 17, 2019

Ah, that works! So the trick is to leave out the optional references in the fixture.

If you don't like digging into this (I had a look at what the builder class does but couldn't figure out if class-transformer takes the typeorm annotations into account), I think a sentence in the docs would suffice.

@RobinCK RobinCK closed this as completed Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants