当前位置:网站首页>Attribute keywords aliases, calculated, cardinality, ClientName

Attribute keywords aliases, calculated, cardinality, ClientName

2022-07-07 13:52:00 User 7741497

Chapter 93 Attribute keyword - Aliases

Specify a different name for this property , In order to use through object access .

usage

To specify a different name for the attribute , Please use the following syntax :

Property name As classname [ Aliases=othernames ]; 

among othernames Is a comma separated list of valid attribute names , Enclosed in braces .

Detailed explanation

If you specify an alias keyword , The compiler will create one or more given aliases , These aliases point to the same basic data that the original attribute points to . for example , Redefinition Sample.Person Of Name attribute , As shown below :

Property Name As %String(POPSPEC = "Name()") [ Aliases = {Alternate}, Required ];

then , The code can be used Name Attribute or equivalent Alternate attribute , As shown in the following terminal session :

SAMPLES>set p=##class(Sample.Person).%OpenId(1)
 
SAMPLES>w p.Name
Fripp,Charles Z.
SAMPLES>w p.Alternate
Fripp,Charles Z.
SAMPLES>set p.Alternate="Anderson,Neville J."
 
SAMPLES>w p.Name
Anderson,Neville J.

Any attribute method associated with the original attribute is also defined for each alias attribute , So in this case ,AlternateIsValid() It's callable , And back with NameIsValid() The same result . Besides , If the attribute method is overridden ( for example , Write custom NameGet() Method ), Then the override will be automatically applied to one or more alias properties .

Be careful : This keyword is for attribute SQL Projection has no effect .

Default

By default , This keyword is NULL, And the attribute has no alias .

Example

Property PropA As %String [ Aliases={OtherName,OtherName2} ]; 

Chapter 94 Attribute keyword - Calculated

Specifies that when instantiating an object containing this property , There is no memory allocated for it .

usage

To specify that no in memory storage is allocated for this attribute , Please use the following syntax :

Property name As classname [ Calculated ];

otherwise , Please omit the keyword or put the word before the keyword .

Detailed explanation

This keyword specifies that when instantiating an object containing this attribute , No memory storage is allocated for this attribute .

When defining attributes that do not require any memory storage , Please use this keyword . There are two ways to specify the value of this property :

  • Defining properties get( There may be set) Method . for example , about Age attribute , Can provide AgeGet Method , This method is based on the current time and DateOfBirth The value of the attribute determines a person's current age .
  • Define this attribute as a calculation attribute ; It USES SqlComputed Keywords and related keywords .

Subclasses inherit calculated keywords , It cannot be rewritten .

Default

Calculated The default value of the keyword is False.

Property Age as %Integer [ Calculated ];

Chapter 95 Attribute keyword - Cardinality

Specify the cardinality of this relationship property cardinality. Relationship properties Required. Not used for other properties .

usage

To specify the cardinality of the Relationship Attribute , Please use the following syntax :

Relationship relname As classname [ Cardinality = cardinality; inverse = inverse ];

among cardinality Is one of the following :

  • one
  • many
  • parent
  • children

Detailed explanation

This keyword specifies the Relationship Attribute cardinality.

Relationship attributes need cardinality keyword . It is ignored by non relational attributes .

Default

No default . When defining relationships , Must specify Cardinality keyword .

Example

Relationship Chapters As Chapter [ Cardinality = many; inverse = Book ];

Chapter 96 Attribute keyword - ClientName

Specify the alias used by the client projection of this property .

usage

To override the default name of this property when projecting a class to the client language , Please use the following syntax :

Property name As classname [ ClientName = clientname ];

among clientname Is the name used in the client language .

Detailed explanation

When attributes are projected to the client language , This keyword allows you to define alternative names for attributes . If the attribute name contains characters that are not allowed in the client language , This is especially useful .

Default

If you omit this keyword , The attribute name will be used as the client name .

原网站

版权声明
本文为[User 7741497]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071146402544.html