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

feat(loadrelationids): @Crud decorator accepts loadRelationIds query … #813

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qstyler
Copy link

@qstyler qstyler commented Dec 9, 2022

…param

Allows @Crud decorator accept loadRelationIds query param that is later accepted by TypeORM.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • The commit message was generated by yarn commit

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] Tests
[ ] Release
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behaviour?

Introduces loadRelationIds, a new field in QueryOptions. That is passed to TypeORM.

This allows the loading of relations ids in objects without joining the whole table.

For example this controller:

@Crud({
  model: { type: UserLicense },
  query: {
    loadRelationIds: {
      relations: ['license'],
      disableMixedMap: true,
    },
  },
})
@Controller('user.licenses')
class UserLicenseController {
  constructor(public service: UserLicenseService) {}
}

getting all records will return this:

[
  {
    "userId": 1,
    "licenseId": 1,
    "yearsActive": 3,
    "license": {
      "id": 1
    }
  },
  {
    "userId": 1,
    "licenseId": 2,
    "yearsActive": 5,
    "license": {
      "id": 2
    }
  },
  {
    "userId": 1,
    "licenseId": 4,
    "yearsActive": 7,
    "license": {
      "id": 4
    }
  },
  {
    "userId": 2,
    "licenseId": 5,
    "yearsActive": 1,
    "license": {
      "id": 5
    }
  }
]

This is very useful for building rest APIs without @RelationId() and @Column() hacks.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

…param

Allows `@Crud` decorator accept `loadRelationIds` query param that is later accepted by TypeORM.
@afilp
Copy link

afilp commented Nov 1, 2023

@qstyler This repo seems to not be supported anymore, would you like to submit your PR to this forked repo, which is more up-to-date? Thanks!

https://github.com/gid-oss/dataui-nestjs-crud

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.

2 participants