25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Populate generates values for the SSN property by calling the MakeSSN method of the<br />

MyApp.Utils class:<br />

Set ..SSN = ##class(MyApp.Utils).MakeSSN()<br />

Populate generates values for the Number that are random integers.<br />

The POPSPEC Parameter<br />

Note:<br />

There is also a POPSPEC parameter defined at the class level that controls data<br />

population for an entire class. This is an older mechanism (included for compatibility)<br />

that is replaced by the property-specific POPSPEC parameter.<br />

19.2.1 Populating Embedded <strong>Objects</strong><br />

The Populate method creates data for an embedded object by calling its PopulateSerial<br />

method (which is generated by the %Populate class). This is done by default as long as the<br />

embedded object inherits from the %Populate class and is equivalent to:<br />

Property Home As Address(POPSPEC="##class(Address).PopulateSerial()");<br />

19.2.2 Populating Lists<br />

To populate a list, the syntax for setting the value of POPSPEC is:<br />

Property PropName As TypeName (POPSPEC="MethodName:MaxNo") [Collection= list];<br />

where PropName is a list of type TypeName; MethodName is the populating method for the<br />

property; and MaxNospecifies the maximum number of elements in the list. If maxnum is not<br />

specified, it defaults to 10.<br />

The value ofMethodName depends on the type of list:<br />

• Lists of data types typically use the %PopulateUtils method corresponding to their data<br />

type.<br />

• Lists of persistent objects should use an empty value for MethodName to take advantage<br />

of the default automatic reference population (as occurs for simple, non-collection reference<br />

properties).<br />

• Lists of embedded objects must use the PopulateSerial method.<br />

In the following example, there are lists of several types of data. Colors is a list of strings,<br />

Kids is a list of references to persistent objects, and Addresses is a list of embedded objects:<br />

<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 165

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!