classReadOnlyRootModel
Source: read-only-root-model.
Represents the definition of an asynchronous read-only root model.
Property
Methods
new ReadOnlyRootModel([eventHandlers])
Creates a new asynchronous read-only root model instance.
The name of the model type available as: <instance>.constructor.modelType, returns 'ReadOnlyRootModel'.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
eventHandlers |
Yes |
The event handlers of the instance. |
- Extends
- ModelBase
- Fires
- ReadOnlyRootModel#event:preFetch
- ReadOnlyRootModel#event:postFetch
- Throws
-
Argument error: The event handlers must be an EventHandlerList object or null.
Property
read-only$modelName
string
The name of the model. However, it can be hidden by a model property with the same name.
Methods
staticfetch([filter][, method][, eventHandlers], callback)
Retrieves a read-only business object from the repository.
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
filter |
any type |
Yes |
The filter criteria. |
|
method |
string |
Yes |
An alternative fetch method of the data access object. |
|
eventHandlers |
Yes |
The event handlers of the instance. |
|
|
callback |
|
Returns the required read-only business object. |
- Throws
-
Argument error: The method must be a string or null.
-
Argument error: The event handlers must be an EventHandlerList object or null.
-
Argument error: The callback must be a function.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Fetching the business object has failed.
checkRules()
Executes all the validation rules of the business object, including the ones of its child objects.
By default read-only business objects are supposed to be valid.
protectedfetch([filter][, method], callback)
Initializes a business object to be retrieved from the repository.
This method is called by a factory method with the same name.
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
filter |
any type |
Yes |
The filter criteria. |
|
method |
string |
Yes |
An alternative fetch method of the data access object. |
|
callback |
|
Returns the required read-only business object. |
- Throws
-
Argument error: The method must be a string or null.
-
Argument error: The callback must be a function.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Fetching the business object has failed.
getBrokenRules([namespace]) → bo.rules.BrokenRulesOutput
Gets the broken rules of the business object.
By default read-only business objects are supposed to be valid.
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
namespace |
string |
Yes |
The namespace of the message keys when messages are localizable. |
- Returns
-
bo.rules.BrokenRulesOutputThe broken rules of the business object.
getResponse([message][, namespace]) → bo.rules.BrokenRulesResponse
Gets the response to send to the client in case of broken rules.
By default read-only business objects are supposed to be valid.
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
message |
string |
Yes |
Human-readable description of the reason of the failure. |
|
namespace |
string |
Yes |
The namespace of the message keys when messages are localizable. |
- Returns
-
bo.rules.BrokenRulesResponseThe broken rules response to send to the client.
isValid() → boolean
Indicates whether all the validation rules of the business object, including the ones of its child objects, succeeds. A valid business object may have broken rules with severity of success, information and warning.
By default read-only business objects are supposed to be valid.
- Returns
-
booleanTrue when the business object is valid, otherwise false.
toCto() → object
Transforms the business object to a plain object to send to the client.
- Returns
-
objectThe client transfer object.
Events
postFetch
The event arises after the business object instance has been retrieved from the repository.
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
eventArgs |
|
Data portal event arguments. |
|
|
newObject |
|
The instance of the model after the data portal action. |
preFetch
The event arises before the business object instance will be retrieved from the repository.
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
eventArgs |
|
Data portal event arguments. |
|
|
oldObject |
|
The instance of the model before the data portal action. |