-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(cli): add hasOne relation type to lb4 relation
#4171
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
Conversation
5ff4908 to
6c32ea3
Compare
|
@lokesh1197, thanks for the PR! Could you please add some tests? Here is some reference: https://github.com/strongloop/loopback-next/tree/master/packages/cli/test/integration/generators. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lokesh1197 I think you forgot to commit index.js and util.generator.js which contains the registration of hasOne.
Error: Generation is aborted: Error: Incorrect relation type
This are the related lines:
https://github.com/strongloop/loopback-next/blob/5bf50b7544573111e693096a9668f73d0ab18e49/packages/cli/generators/relation/utils.generator.js#L13-L16
should be:
exports.relationType = {
belongsTo: 'belongsTo',
hasMany: 'hasMany',
hasOne: 'hasOne',
};Error: Generation is aborted: TypeError: Cannot read property 'generateAll' of undefined
This are the related lines:
https://github.com/strongloop/loopback-next/blob/5bf50b7544573111e693096a9668f73d0ab18e49/packages/cli/generators/relation/index.js#L411-L421
should be:
switch (this.artifactInfo.relationType) {
case relationUtils.relationType.belongsTo:
relationGenerator = new BelongsToRelationGenerator(
this.args,
this.opts,
);
break;
case relationUtils.relationType.hasMany:
relationGenerator = new HasManyRelationGenerator(this.args, this.opts);
break;
case relationUtils.relationType.hasOne:
relationGenerator = new HasOneRelationGenerator(this.args, this.opts);
break;
}
packages/cli/generators/relation/templates/controller-relation-template-has-one.ts.ejs
Outdated
Show resolved
Hide resolved
packages/cli/generators/relation/templates/controller-relation-template-has-one.ts.ejs
Outdated
Show resolved
Hide resolved
|
@lokesh1197 |
109a50e to
ebd9dce
Compare
derdeka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lokesh1197 Looks like you've commited changes which are not relevant for this feature. Can you please revert unrelated changes?
|
@derdeka . Only one test is failing right now with
It would be great if I could receive some help here |
ebd9dce to
9873a53
Compare
|
@agnes512, do you think you can help? Thanks. |
9873a53 to
e6fbce0
Compare
e6fbce0 to
e01f28a
Compare
agnes512
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for picking up the task!
I read through the generator code and the controller template and found some bugs.
Let's improve the implementation parts:
The hasOne relation should be similar to hasMany relation except that the default relation name is not plural. (e.g customer has many orders, customer has one address).
so some generator setup is not correct. has-many-generator would be a good reference.
That's fix the generator and template first, then fix the tests later 💪
packages/cli/generators/relation/templates/controller-relation-template-has-one.ts.ejs
Outdated
Show resolved
Hide resolved
packages/cli/snapshots/integration/generators/relation.has-one.integration.snapshots.js
Outdated
Show resolved
Hide resolved
|
You can use command |
|
This is great contribution, I am looking forward to see it landed 🕺 @agnes512 I'll let you drive the review process, please ping me if you need any help. |
agnes512
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do npm i and npm run build several times might get rid of the error.
But also we can update the snapshot ourselves ( that's how I usually verify the changes). Let's check if the implementations are valid with the updated snapshots.
packages/cli/snapshots/integration/generators/relation.has-one.integration.snapshots.js
Outdated
Show resolved
Hide resolved
packages/cli/snapshots/integration/generators/relation.has-one.integration.snapshots.js
Outdated
Show resolved
Hide resolved
packages/cli/snapshots/integration/generators/relation.has-one.integration.snapshots.js
Outdated
Show resolved
Hide resolved
packages/cli/snapshots/integration/generators/relation.has-one.integration.snapshots.js
Outdated
Show resolved
Hide resolved
packages/cli/snapshots/integration/generators/relation.has-one.integration.snapshots.js
Outdated
Show resolved
Hide resolved
packages/cli/snapshots/integration/generators/relation.has-one.integration.snapshots.js
Outdated
Show resolved
Hide resolved
|
@agnes512 |
Yes that happened to me on my end. The easiest way to fix it is to reclone You can run build inside of |
d4a8118 to
18853d5
Compare
agnes512
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!! I'd love to land it after getting more approvals 😄
|
Thanks a lot for your help 😁 |
derdeka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Impressive changes since my last review. I’ll review and test the implementation tomorrow in detail. I‘m just wondering that more than the half of the PR is about changing the docs and not extending the cli. This should be separate PRs or at least two commits for a clean history and changelog.
18853d5 to
a710382
Compare
|
@derdeka I split the commit into two. Is it fine now? |
derdeka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost working, Here is my feedback:
packages/cli/generators/relation/templates/controller-relation-template-has-one.ts.ejs
Outdated
Show resolved
Hide resolved
packages/cli/generators/relation/templates/controller-relation-template-has-one.ts.ejs
Outdated
Show resolved
Hide resolved
packages/cli/generators/relation/templates/controller-relation-template-has-one.ts.ejs
Show resolved
Hide resolved
packages/cli/generators/relation/templates/controller-relation-template-has-one.ts.ejs
Outdated
Show resolved
Hide resolved
emonddr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @lokesh1197
|
@lokesh1197 , we're almost there. Can you please address @derdeka 's last comments? Let's try to land this PR today or tomorrow. :) |
|
@derdeka ^ |
a710382 to
92ab010
Compare
|
Going to kick off the CI again. Hopefully the failing tests will pass. |
|
@slnode test please |
@emonddr The failing tests are caused by the changes. The snapshots need to be updated. And I don't think |
92ab010 to
f66788c
Compare
|
I have updated the snapshots file |
f66788c to
fdffe28
Compare
fdffe28 to
bd15c3a
Compare
jannyHou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
yay! |
Fixes #2980