-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs: update Models.md #4829
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
docs: update Models.md #4829
Conversation
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.
👍 LGTM in general good update! a few nitpicks.
I think lb3 uses scopes instead of scope?
| ``` | ||
|
|
||
| ### Property Decorator | ||
| ### Scope |
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.
| ### Scope | |
| ### Scopes |
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.
The field name is in plural :p https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#scopes
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.
Yes, but in LB4 it only works with settings scope:
@model({
settings: {
scope: {
'limit': 2,
},
idInjection: true
}
}):( that's why I made them scope instead of scopes
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.
I see! remembered, LB3 supports both scopes and scope:
- scopes: a collection of predefined scopes
- scope: the default scope
So your change makes perfect sense 💯
docs/site/Model.md
Outdated
| ```ts | ||
| { | ||
| name: "Product", | ||
| scope: { |
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.
| scope: { | |
| scopes: { |
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.
And I think you need to give each scope a name?
Like
"scopes": {
"vips": {"where": {"vip": true}},
"top5": {"limit": 5, "order": "age"}
}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.
I don't think this part works in LB4, at least from what I tried.
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.
👍 take my comment back :p
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.
Just want to double check this part: in LB3 we allow:
"scopes": {
"vips": {"where": {"vip": true}},
"top5": {"limit": 5, "order": "age"}
}then the scopes can be used as
User.scope("vips", { where: { vip: true } });
User.scope("top5", { limit: 5, order: "age" });I don't think this is valid in LB4 because:
Usermodel, or any lb4 model, doesn't have such methodscope- LB4 uses repositories to query data. So
User.scopewon't work.
Is this correct?
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.
Defining
"scopes": {
"vips": {"where": {"vip": true}},
"top5": {"limit": 5, "order": "age"}
}is equivalent to
// please note User.scope defines scope, not apply scope
User.scope("vips", { where: { vip: true } });
User.scope("top5", { limit: 5, order: "age" });After defining them, you can call APIs like User.vips() to query with the predefined filter.
But your conclusion is correct 👌 we don't have such APIs in User repository. Therefore scopes won't be supported. Only specifying the default scope works.
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.
💯 LGTM
nabdelgadir
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 👏
|
Even the settings can be imported from LB3, see https://github.com/strongloop/loopback-next/pull/4737/files#r383816292, I've decided to remove We can revert the change if ^ the conclusion is incorrect. |
clean up old content and make it less relate to lb3 some content are copied from lb3 and rewrite it with lb4-way
clean up old content and make it less relate to lb3
some content are copied from lb3 and rewrite it with lb4-way
closes loopbackio/loopback.io#907
While doing ^907, I realized that we link to LB3 docs a lot. Considering there are several differences between them and not all users are familiar with LB3, I think it's time to separate them. ( And ofc it is also annoying to jump back and forth between LB3 and LB4 docs)
So I edited the
Model DecoratorandProperty Decoratorsections that:I tested them briefly before I removing some features/entries. If you happen to know that they are still available but got deleted, please kindly let me know, thanks!!
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈