# new UBEntity (entityInfo: object, entityMethods: object, i18n: object, entityCode: string, domain: UBDomain)
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.
# 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 (methodName: string) 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:
methodName
: string
//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 (attributesAsArrayopt: boolean, removeAttrsAddedByMixinopt: boolean) → 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
# attr (attributeCode: string, simpleOnlyopt: boolean) → UBEntityAttribute instance
Get entity attribute by code. Return undefined
if attribute is not found
# checkAttributeExist (attributeNames: string | Array.<string>, contextMessage: string) instance
Checks entity has attribute(s) and throw error if not
# checkMixin (mixinCode: string) instance
Checks if entity has mixin. Throw if mixin does not exist or not enabled
Arguments:
mixinCode
: string
# eachAttribute (callBack: entityAttributesIteratorCallback) → object instance
Iterates over entity attributes. The iteratee is invoked with three arguments: (UBEntityAttribute, attributeName, UBEntityAttributes)
Arguments:
callBack
: entityAttributesIteratorCallback
# filterAttribute (predicate: object) → Array.<UBEntityAttribute> instance
Filters attributes by properties
// return all attributes where property dataType equal Document
domain.get('uba_user').filterAttribute({dataType: 'Document'});
# getAttribute (attributeCode: string) → UBEntityAttribute instance
Get entity attribute by code. Throw error if attribute is not found
Arguments:
attributeCode
: string
# getAttributeNames (predicateopt: object) → Array.<string> instance
Returns array of entity attribute`s names
Arguments:
predicate
: object| functionSee UBEntity.filterAttribute. If empty - will return all names
# getConvertRules (fieldList: Array.<string>) → Array.<{index: number, convertFn: function()}> instance
Return array of conversion rules for raw server response data
# getDescriptionAttribute (raiseErrorIfNotExistsopt: boolean) → string | undefined instance
Returns description attribute name (descriptionAttribute
metadata property)
If descriptionAttribute
is empty - fallback to attribute with code caption
Arguments:
raiseErrorIfNotExists
= true: booleanIf
true
(default) and description attribute does not exist throw error, iffalse
- returnundefined
# 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 (attributeName: string, depthopt: number) → UBEntityAttribute instance
Returns entity attribute. Understand complex attributes like firmID.firmType.code
# getEntityAttributeInfo (attributeName: string, depthopt: number) → 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:
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 (fieldListopt: Array.<string>) → Array.<string> instance
For each attribute of type Entity
from fieldList
add entity code to result (duplicates are removed)
# hasMixin (mixinCode: string) → boolean instance
Checks if entity has enabled mixin with specified code
Arguments:
mixinCode
: string
# haveAccessToAnyMethods (methodsCodes: Array.<string>) → boolean instance
Checks if current user has access to at last one of specified methods
# haveAccessToMethod (methodCode: string) → boolean instance
Checks if current user has access to a specified entity method
Arguments:
methodCode
: string
# haveAccessToMethods (methods: Array.<string>) → boolean instance
Checks if current user has access to ALL the specified methods
# mixin (mixinCode: string) → UBEntityMixin instance
Get entity mixin by code. Returns undefined
if mixin is not found
Arguments:
mixinCode
: string