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

selected fields on joins don't work #510

Closed
jbrousseau opened this issue May 14, 2020 · 3 comments
Closed

selected fields on joins don't work #510

jbrousseau opened this issue May 14, 2020 · 3 comments

Comments

@jbrousseau
Copy link

First thank you for this awesome library!

According to documentation:

join
Receive joined relational objects in GET result (with all or selected fields)
?join=relation||field1,field2

But when I use field1, field2 in the HTTP query, it doesn't select these fields (I tried with latest v4.6.1). Instead, it select all the allowed fields defined in CrudOptions.

It's seems that it is due to the fact that in:
packages/crud-typeorm/src/typeorm-crud.service.ts

In function setJoin

      const select = [
        ...allowedRelation.primaryColumns,
        ...(options.persist && options.persist.length ? options.persist : []),
        ...allowedRelation.allowedColumns,
      ].map((col) => `${alias}.${col}`);

There is some filter missing somewhere, like this one (Note: I haven't tested yet the modification code below):

      const select = [
        ...allowedRelation.primaryColumns,
        ...(options.persist && options.persist.length ? options.persist : []),
        ...allowedRelation.allowedColumns,
      ]
     .filter((col) => !cond.select?.length || cond.select.includes(col)
     .map((col) => `${alias}.${col}`);

Thanks you for your feedback!

@michaelyali
Copy link
Member

Thanks, I'll check it right now

@michaelyali
Copy link
Member

fixed with v4.6.2

@jbrousseau
Copy link
Author

wow, awesome, thank you!

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

No branches or pull requests

2 participants