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(cli): add option to create relations in cli discover command #8461

Merged
merged 1 commit into from
May 20, 2022

Conversation

sohaibahsan007
Copy link
Contributor

@sohaibahsan007 sohaibahsan007 commented Apr 2, 2022

Added a new option in discover CLI command relations. If true, relations are discovered from the datasource and added to models. Relations are discovered by settings associations property in modelMaker.discoverSingleModel options to true. Then we map the discovered relations onto the properties object and also created arrays for relation and destination model imports. Because discover generator uses model generator's model.ts.ejs template file. we have updated this template file to include relation imports and property relations.

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

@coveralls
Copy link

coveralls commented Apr 2, 2022

Pull Request Test Coverage Report for Build 2358794873

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 2 of 22 (9.09%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 76.777%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/cli/generators/discover/index.js 2 22 9.09%
Totals Coverage Status
Change from base Build 2358717211: 0.3%
Covered Lines: 17999
Relevant Lines: 18970

💛 - Coveralls

@achrinza achrinza self-requested a review April 3, 2022 22:54
Comment on lines +350 to +377
// Delete relation from modelSettings
delete templateData.settings.relations;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some connectors support "strong relations" (i.e. Constraints enforced by the database engine) through @model({settings: {foreignKeys: {/* ... */}}). Can we populate that field as well?

See https://github.com/loopbackio/loopback-connector-mysql/tree/f8f40a1199b6ed63ba01d6d173a9314004c08c93#auto-migrateauto-update-models-with-foreign-keys for an example of the syntax.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achrinza Thank you for the review. and sure we can do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achrinza, we have updated the code to populate foreignKeys in model settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @achrinza,
The Soap-calculator example uses a soap service link https://calculator-webservice.mybluemix.net/ for sending HTTP requests. This link is now returning 404 on all requests and because of that related tests are failing. We are unable to get our PRs merged because of these failed tests.
This is the link for datasource of soap-service.
https://github.com/loopbackio/loopback-next/blob/master/examples/soap-calculator/src/datasources/calculator.datasource.ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sohaibahsan007, we're aware of the issue and looking into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@awaissaeedforenax awaissaeedforenax force-pushed the discover-relations branch 2 times, most recently from e567200 to 8f1ec57 Compare May 17, 2022 17:06
Comment on lines +353 to +370
x => x?.[1].id === 1,
)?.[0],
foreignKey: relation.foreignKey,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note for myself: We'll need to figure out how to handle composite foreign keys in the future.

@achrinza
Copy link
Member

Just need to squash the commit, and it should be good to merge.

@sohaibahsan007
Copy link
Contributor Author

@achrinza commits have been squashed.

@achrinza
Copy link
Member

achrinza commented May 20, 2022

Hi @sohaibahsan007, sorry to bother again - But we'll need to resolve the merge conflict.

In future PRs, you could consider using a fork from your personal GitHub account, which would allow the maintainers to push changes from our end.

More info about this feature can be found here:

@sohaibahsan007
Copy link
Contributor Author

@achrinza we have resolved the conflict, Please merge it. and we will keep in mind for future PRs.

@achrinza achrinza merged commit 37a5f73 into loopbackio:master May 20, 2022
@achrinza
Copy link
Member

Thanks for your contributions! They've been merged 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants