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

fix(cli): add 'generated: true' entry to id property when generating #3643

Merged
merged 1 commit into from
Sep 6, 2019

Conversation

agnes512
Copy link
Contributor

@agnes512 agnes512 commented Sep 3, 2019

connect to #3538

We found in refactor test PR that id needs to be generated for any instances for the mysql tests, otherwise it complains with Error: ER_NO_DEFAULT_FOR_FIELD: Field 'id' doesn't have a default value.
It's not required for relations. But it might be problematic if models are migrated to databases such MySQL.

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • 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

👉 Check out how to submit a PR 👈

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

LGTM.

Is there a (reasonably easy) way how to write a test for this new execution path?

@agnes512
Copy link
Contributor Author

agnes512 commented Sep 3, 2019

Is there a (reasonably easy) way how to write a test for this new execution path?

The test for this functionality only makes sense for MySQL since in-memory and mongo generate ids automatically without generated: true.
It can only be tested in the repository-test folder. I don't think it makes sense to add a generator test in that folder though. Any suggestions?


if (answers.id) {
// 'generated' makes sure id is defined, especially for database like MySQL
answers['generated'] = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a prompt to ask if the id is automatically generated by the database?

Copy link
Member

Choose a reason for hiding this comment

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

+1 to add a prompt. The topic is more complex though because of the model-level setting forceId.

Let's land this PR as an incremental improvement and open a new issue to investigate what changes are needed to support models where the PK is provided by clients (not generated by the DB).

@raymondfeng raymondfeng mentioned this pull request Sep 4, 2019
7 tasks
@bajtos
Copy link
Member

bajtos commented Sep 5, 2019

Is there a (reasonably easy) way how to write a test for this new execution path?

The test for this functionality only makes sense for MySQL since in-memory and mongo generate ids automatically without generated: true.
It can only be tested in the repository-test folder. I don't think it makes sense to add a generator test in that folder though. Any suggestions?

I agree with you that we don't want to run lb4 from repository-test tests, that would make them super slow!

I was thinking about a test that will call lb4 model and then check the generated model .ts file to verify that generated: true is included in id's @property metadata.

@agnes512 agnes512 force-pushed the model-id-generated branch 5 times, most recently from 6c33325 to 193b941 Compare September 5, 2019 19:56
@agnes512 agnes512 merged commit 28cef4e into master Sep 6, 2019
@agnes512 agnes512 deleted the model-id-generated branch September 6, 2019 17:42
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.

3 participants