# new UBEntity (entityInfoobject, entityMethodsobject, i18nobject, entityCodestring, domainUBDomain)

Arguments:

Members

# attributes : Object.<string, UBEntityAttribute> instance

Entity attributes collection

# blobAttributes : Array.<UBEntityAttribute> instance

Slice of attributes with type Document

# cacheType : UBDomain.EntityCacheTypes instance

Indicate how entity content is cached on the client side.

# caption : string instance

Entity caption in plural

# captionSingular : string instance

Entity caption in singular

# code : string instance

# connectionConfig : DBConnectionConfig instance

Reference to connection definition (for extended domain only)

# connectionName : string instance

Data source connection name

# customSettings instance

Custom settings

Name Type Description
customSettings object

# dbExtensions : object instance

Optional dbExtensions (for extended domain info)

# dbKeys : object instance

Optional dbKeys (for extended domain info)

# description : string instance

Entity description

# descriptionAttribute : string instance

Name of attribute witch used as a display value in lookup

# documentation : string instance

Documentation

# dsType : UBDomain.EntityDataSourceType instance

# entityMethods : Object.<string, number> instance

Entity methods, allowed for current logged-in user in format {method1: 1, method2: 1}. 1 mean method is allowed Empty for server-side domain - use entity.haveAccessToMethod to check method is accessible for user

# isFTSDataTable : boolean instance

This is a Full Text Search entity

# isManyManyRef : boolean instance

Indicate this entity is a many-to-many storage for attributes of type "Many"

# isUnity : boolean instance

Indicate this entity is a UNITY for someone

# mapping : UBEntityMapping instance

Optional mapping of entity to physical data (for extended domain info only). Calculated from a entity mapping collection in accordance with application connection configuration

# mixins : Object.<string, UBEntityMixin> instance

Collection of entity mixins

# modelName : string instance

Name of model where entity is defined (in case entity is overridden - see overridesBy)

# name : string instance

Entity name

# overriddenBy : string instance

CSV model names where entity is overridden

# sqlAlias : string instance

Internal short alias

Methods

# addMethod (methodNamestring) instance

Add entity level method. Client can call such methods remotely. Also such methods are the subjects of ELS.

Property named methodName with a type function should be added to the entity namespace. Such functions accept single parameter of type ubMethodParams

Don't add methods what do not called from client using {@UBEntity#addMethod}!

Warning: do not call UBEntity.addMethod from inside function or conditions. This code evaluated during thread initialization and each thread must add method in the same manner.

Arguments:
  
      //consider entity with code `my_entity` exists. Inside my_entity.js file):
 var me = my_entity;
 me.entity.addMethod('externalMethod');
 // @param {ubMethodParams} ctx <- here must be JSDoc comment format
 me.externalMethod = function (ctx) {
   let params = ctx.mParams
   let a = params.a || 1
   let b = params.b || 1
   params.multiplyResult = a*b
 }

 // now from client side you can call
 $App.connection.query({entity: 'my_entity', method: 'externalMethod', a: 10, b:20}).then(function(result){
   console.log(' 10 * 20 = ', result.multiplyResult); // will put to log "10 * 20 = 200"
 })
  

# asPlainJSON (attributesAsArrayoptboolean, removeAttrsAddedByMixinoptboolean) → any instance

Return a JSON representation entity WITHOUT properties which have default values Result is very close to meta file.

WARNING use carefully inside server thread - method is slow

Arguments:
  • attributesAsArray = true: boolean
  • removeAttrsAddedByMixin = true: boolean

# attr (attributeCodestring, simpleOnlyoptboolean) → UBEntityAttribute instance

Get entity attribute by code. Return undefined if attribute is not found

Arguments:
  • attributeCode: string
  • simpleOnly = false: boolean

    If false(default) - parse complex attributes like attr1.attr2.attr3

# checkAttributeExist (attributeNamesstring | Array.<string>, contextMessagestring) instance

Checks entity has attribute(s) and throw error if not

Arguments:

# checkMixin (mixinCodestring) instance

Checks if entity has mixin. Throw if mixin does not exist or not enabled

Arguments:

# eachAttribute (callBackentityAttributesIteratorCallback) → object instance

Iterates over entity attributes. The iteratee is invoked with three arguments: (UBEntityAttribute, attributeName, UBEntityAttributes)

# filterAttribute (predicateobject) → Array.<UBEntityAttribute> instance

Filters attributes by properties

Arguments:
  
      // return all attributes where property dataType equal Document
   domain.get('uba_user').filterAttribute({dataType: 'Document'});
  

# getAttribute (attributeCodestring) → UBEntityAttribute instance

Get entity attribute by code. Throw error if attribute is not found

Arguments:

# getAttributeNames (predicateoptobject) → Array.<string> instance

Returns array of entity attribute`s names

Arguments:

# getConvertRules (fieldListArray.<string>) → Array.<{index: number, convertFn: function()}> instance

Return array of conversion rules for raw server response data

Arguments:

# getDescriptionAttribute (raiseErrorIfNotExistsoptboolean) → string | undefined instance

Returns description attribute name (descriptionAttribute metadata property) If descriptionAttribute is empty - fallback to attribute with code caption

Arguments:
  • raiseErrorIfNotExists = true: boolean

    If true(default) and description attribute does not exist throw error, if false - return undefined

# getDetailsForUI () → Array.<UBEntityAttribute> instance

Returns an array of UBEntityAttribute with "Entity" data type and pointing to this entity (associatedEntity === this entity) and such relation should be visible in the UI "Details" menu.

Excluded attributes are:

  • mi_* attributes
  • attributes with customSetting.hiddenInDetails === true
  • all attributes for entities user do not have access to the select method

# getEntityAttribute (attributeNamestring, depthoptnumber) → UBEntityAttribute instance

Returns entity attribute. Understand complex attributes like firmID.firmType.code

Arguments:
  • attributeName: string
  • depth = 0: number

    Current recursion depth

    • 0 means last attribute in chain (code from above)
    • -1 - before last (firmType from above)
    • >0 - first (firmID from above)

# getEntityAttributeInfo (attributeNamestring, depthoptnumber) → Object | undefined instance

Returns information about attribute and attribute entity. Understand complex attributes like firmID.firmType.code

Return:

Either attribute information or undefined if chain not points to attribute

Arguments:
  • attributeName: string
  • depth = 0: number

    If 0 - last, -1 - before last, > 0 - first. Default 0.

    • 0 means last attribute in chain (code from above)
    • -1 - before last (firmType from above)
    • >0 - first (firmID from above)

  
      UB.connection.domain.get('cdn_country').getEntityAttributeInfo('mi_modifyUser.name')
 // {entity: 'uba_user', attribute: 'name', parentAttribute: {code: mi_modifyUser, dataType: 'Entity', ....}}
  

# getEntityCaption () → string instance

Return an entity caption to display on UI

# getEntityDescription () → string instance

Return entity description

# getEntityRequirements (fieldListoptArray.<string>) → Array.<string> instance

For each attribute of type Entity from fieldList add entity code to result (duplicates are removed)

Arguments:
  • fieldList: Array.<string>

    If empty - all entity attributes will be used

# hasMixin (mixinCodestring) → boolean instance

Checks if entity has enabled mixin with specified code

Arguments:

# haveAccessToAnyMethods (methodsCodesArray.<string>) → boolean instance

Checks if current user has access to at last one of specified methods

Arguments:

# haveAccessToMethod (methodCodestring) → boolean instance

Checks if current user has access to a specified entity method

Arguments:

# haveAccessToMethods (methodsArray.<string>) → boolean instance

Checks if current user has access to ALL the specified methods

Arguments:

# mixin (mixinCodestring) → UBEntityMixin instance

Get entity mixin by code. Returns undefined if mixin is not found

Arguments: