DataModel

most-data/data-classes. DataModel

DataModel class extends a JSON data model and performs all data operations (select, insert, update and delete) in MOST Data Applications.

These JSON schemas are in config/models folder:


 /
 + config
   + models
     - User.json
     - Group.json
     - Account.json
     ...
 

The following JSON schema presents a typical User model with fields, views, privileges, constraints, listeners, and seeding:


 {
     "name": "User", "id": 90, "title": "Application Users", "inherits": "Account", "hidden": false, "sealed": false, "abstract": false, "version": "1.4",
     "fields": [
         {
             "name": "id", "title": "Id", "description": "The identifier of the item.",
             "type": "Integer",
             "nullable": false,
             "primary": true
         },
         {
             "name": "accountType",  "title": "Account Type", "description": "Contains a set of flags that define the type and scope of an account object.",
             "type": "Integer",
             "readonly":true,
             "value":"javascript:return 0;"
         },
         {
             "name": "lockoutTime", "title": "Lockout Time", "description": "The date and time that this account was locked out.",
             "type": "DateTime",
             "readonly": true
         },
         {
             "name": "logonCount", "title": "Logon Count", "description": "The number of times the account has successfully logged on.",
             "type": "Integer",
             "value": "javascript:return 0;",
             "readonly": true
         },
         {
             "name": "enabled", "title": "Enabled", "description": "Indicates whether a user is enabled or not.",
             "type": "Boolean",
             "nullable": false,
             "value": "javascript:return true;"
         },
         {
             "name": "lastLogon", "title": "Last Logon", "description": "The last time and date the user logged on.",
             "type": "DateTime",
             "readonly": true
         },
         {
             "name": "groups", "title": "User Groups", "description": "A collection of groups where user belongs.",
             "type": "Group",
             "expandable": true,
             "mapping": {
                 "associationAdapter": "GroupMembers", "parentModel": "Group",
                 "parentField": "id", "childModel": "User", "childField": "id",
                 "associationType": "junction", "cascade": "delete",
                 "select": [
                     "id",
                     "name",
                     "alternateName"
                 ]
             }
         },
         {
             "name": "additionalType",
             "value":"javascript:return this.model.name;",
             "readonly":true
         },
         {
             "name": "accountType",
             "value": "javascript:return 0;"
         }
     ], "privileges":[
         { "mask":1, "type":"self", "filter":"id eq me()" },
         { "mask":15, "type":"global", "account":"*" }
     ],
     "constraints":[
         {
             "description": "User name must be unique across different records.",
             "type":"unique",
             "fields": [ "name" ]
         }
     ],
     "views": [
         {
             "name":"list", "title":"Users", "fields":[
                 { "name":"id", "hidden":true },
                 { "name":"description" },
                 { "name":"name" },
                 { "name":"enabled" , "format":"yesno" },
                 { "name":"dateCreated", "format":"moment : 'LLL'" },
                 { "name":"dateModified", "format":"moment : 'LLL'" }
             ], "order":"dateModified desc"
         }
     ],
     "eventListeners": [
         { "name":"New User Credentials Provider", "type":"/app/controllers/user-credentials-listener" }
     ],
     "seed":[
         {
             "name":"anonymous",
             "description":"Anonymous User",
             "groups":[
                 { "name":"Guests" }
             ]
         },
         {
             "name":"admin@example.com",
             "description":"Site Administrator",
             "groups":[
                 { "name":"Administrators" }
             ]
         }
     ]
 }
 

Constructor

new DataModel(objopt)

Parameters:
Name Type Attributes Description
obj * <optional>
An object instance that holds data model attributes. This parameter is optional.
Properties:
Name Type Description
classPath string Gets or sets a string which represents the path of the DataObject subclass associated with this model.
name string Gets or sets a string that represents the name of the model.
id number Gets or sets an integer that represents the internal identifier of the model.
hidden boolean Gets or sets a boolean that indicates whether the current model is hidden or not. The default value is false.
title string Gets or sets a title for this data model.
sealed boolean Gets or sets a boolean that indicates whether current model is sealed or not. A sealed model cannot be migrated.
abstract boolean Gets or sets a boolean that indicates whether current model is an abstract model or not.
version string Gets or sets the version of this data model.
type string Gets or sets an internal type for this model.
caching DataCachingType | string Gets or sets a string that indicates the caching type for this model. The default value is none.
inherits string Gets or sets a string that contains the model that is inherited by the current model.
fields Array.<DataField> Gets or sets an array that represents the collection of model fields.
eventListeners Array.<DataModelEventListener> Gets or sets an array that represents the collection of model listeners.
constraints Array Gets or sets the array of constraints which are defined for this model
views Array.<DataModelView> Gets or sets the array of views which are defined for this model
privileges Array.<DataModelPrivilege> Gets or sets the array of privileges which are defined for this model
source string Gets or sets a string which represents the source database object for this model.
view string Gets or sets a string which represents the view database object for this model.
DataContext | * Gets or sets the data context of this model.
attributes Array.<DataField> Gets an array of DataField objects which represents the collection of model fields (including fields which are inherited from the base model).
seed Array An array of objects which represents a collection of items to be seeded when the model is being generated for the first time
Source:

Extends

  • EventEmitter2