diff --git a/docs/site/Model.md b/docs/site/Model.md index 1887a4eb6847..b104a542ea02 100644 --- a/docs/site/Model.md +++ b/docs/site/Model.md @@ -157,30 +157,28 @@ class MyFlexibleModel extends Entity { ### Model Decorator The model decorator can be used without any additional parameters, or can be -passed in a +passed in a ModelDefinitionSyntax: - -[ModelDefinitionSyntax](https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html) -object which follows the general format provided in LoopBack 3: + ```ts @model({ name: 'Category', - properties: { - // define properties here. - }, settings: { // etc... }, + // define properties by @property decorator below }) class Category extends Entity { // etc... + @property({type: 'number'}) + categoryId: number; } ``` -However, the model decorator already knows the name of your model class, so you -can omit it. +The model decorator already knows the name of your model class, so you can omit +it. ```ts @model() @@ -190,9 +188,197 @@ class Product extends Entity { } ``` -Additionally, the model decorator is able to build the properties object through -the information passed in or inferred by the property decorators, so the -properties key value pair can also be omitted. +However, the model decorator in LoopBack 4 is not exactly the same as what it is +in LoopBack 3. For example, in +[lb3](https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html) we can +pass in a model definition syntax in the model decorator, such as properties, +options, relation etc. But not all these entries are available in lb4 model +decorator: + + + +NOTICE: in LoopBack 4 we only support `settings` in the ModelDefinitionSyntax +for now. Those `top-level properties` in lb3 now are passed in `settings`. + +- `properties` now are defined in `@property` decorator (see below for more + information). +- [`options`](https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#options) + in lb3 doesn't have the mapping feature in LB4 yet. (see + [issue #2142](https://github.com/strongloop/loopback-next/issues/2142) for + further discussion.) + +As for entries in `settings`, LoopBack 4 supports these built-in entries for +now: + +#### Supported Entries of Settings + + + +
| Property | +Type | +Default | +Description | +
|---|---|---|---|
description |
+ String | +None | ++ Optional description of the model. We only support string type for now. (see issue #3428 for more discussion.) + |
forceId |
+ Boolean | +true |
+ + If true, prevents clients from setting the auto-generated ID value manually. + | +
strict |
+ Boolean or String | +true. |
+
+ In LB4, the default for this entry is set to be true.+ Specifies whether the model accepts only predefined properties or not. One of: +
|
+
idInjection |
+ Boolean | +true |
+
+ Whether to automatically add an id property to the model:
+
idInjection property in options (if present) takes precedence.
+ |
+
name |
+ String | +None | +Name of the model. | +
scopes |
+ Object | +N/A | +See Scopes in lb3 docs. | +
| Property | +Description | +
|---|---|
acls |
+ + (TBD) + | +
base |
+ This entry is no longer being used. This is done by the typical Js/Tsc classes inheritance way in LB4:
+ |
+
excludeBaseProperties |
+ (TBD) | +
http |
+ This entry affects HTTP configuration in LB3. Since in LB4 http configurations are inferred from controller members and the rest server, this field is not applicable. | +
options |
+ + (TBD) see issue #2142 for further discussion. + | +
plural |
+ This entry is part of HTTP configuration in LB3. So it's not applicable for the same reason as http above. |
+
properties |
+ This entry is no longer being used as we introduced @property decorator in LB4. See @property decorator below to discover moer about how to define properties for your models. |
+
relations |
+
+ With the introduction of repositories, now relations are defined by relations decorators in LB4.
+ See Relations for more details.
+ |
+
remoting. |
+
+ This entry is part of HTTP configuration in LB3. So it's not applicable for the same reason as http above.
+ |
+
replaceOnPUT |
+ This entry is no longer supported as LB4 controllers scaffolded by LB4 controller, PUT is always calling replaceById. Users are free to change the generated code to call patchById if needed. |
+