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

[Bug] new release v0.18.1 broke relationships #493

Closed
yeomann opened this issue Aug 31, 2020 · 5 comments
Closed

[Bug] new release v0.18.1 broke relationships #493

yeomann opened this issue Aug 31, 2020 · 5 comments

Comments

@yeomann
Copy link

yeomann commented Aug 31, 2020

Hi,

Thanks for the great library, we using Nx based multiple apps that extends some entity from core module in multiple Nestjs projects.

we had defined the relationships this way for example in user entity

  @ManyToOne(() => Agent)
  @JoinColumn({ name: 'agent_id' })
  agent?: Agent;

After update to v0.18.1 graphql was broken on accessing the relationships and give the entitymetadata error.
image

we found the fix which is to write the second argument in like this agent => agent.user
due to complexity of the app and sharing of entities from core to multiple nestjs projects, it not possible to pass the second argument in some cases, that is why we had to downgrade to 0.17.10

The above explained scenario was working until the update. It's seems a big bug to be honest.
Kindly can you please check it?
Thanks

@yeomann yeomann changed the title new release v0.18.1 broke relationships [Bug] new release v0.18.1 broke relationships Aug 31, 2020
@doug-martin
Copy link
Owner

@yeomann sorry about that, all my tests assumed the relationships were bi-directional. I'm working on a fix with tests to cover this use case in the future.

@yeomann
Copy link
Author

yeomann commented Sep 1, 2020

Thank you @doug-martin waiting for the fix, appreciate your effort.

@JeffSchofield
Copy link

I'm having this issue as well with uni-directional one-to-one relationships. I started working on a PR but have had only trouble getting tests to run locally.

I did a quick fix by changing line 224 in /packages/query-typeorm/src/query/relation-query.builder.ts to:

    const inverseEntityMetadata = relation.inverseRelation?.entityMetadata ?? relation.inverseEntityMetadata;
    const fromPrimaryKeys = inverseEntityMetadata.primaryColumns.map((pk) => ({

and that got my project working. This could possibly be slimmed down to:

    const fromPrimaryKeys = relation.inverseEntityMetadata.primaryColumns.map((pk) => ({

as I am pretty sure relation.inverseEntityMetadata will be available for both uni-direction and bi-directional relations but I have not been able to write a test case.

@doug-martin
Copy link
Owner

Just issued a PR, @JeffSchofield you were spot on.

Sorry I didn't get this out earlier, spent quite a bit of time writing tests and making sure that they failed with the old code, and didnt break anything else :)

@doug-martin
Copy link
Owner

@yeomann @JeffSchofield just published @nestjs-query/query-typeorm v0.19.1` which should fix this. Let me know if you still run into issues so I can address them!

Thanks for the bug report!

marian2js pushed a commit to marian2js/nestjs-query that referenced this issue Sep 3, 2020
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

3 participants