When using a wwBusProParent, you set properties on the Parent that tell it about the Child class.
Then, the Parent will create the Child class for you.
You do not create the Child when writing your code, let the Parent do that.
You need to create a VCX library and put a Child class for each Child collection in there,
with its Child properties already set up. This allows the Parent to create the Child when he
needs it. If you follow the path of the Get() method, you will see that the Parent creates a
Child class object and attaches it to its oLineItems property. So, once your Child classes are
configured in a VCX, you will not actually have to write any code to access them (unless you are
doing some special case, custom coding), you just set up the Parent so he can find them.
The Parent will handle all that for you, including the fetching of the related Child records.
You can also put your Parent objects in the VCX and set their properties in the VCX file.
This sample code is shown here simply to show which properties are required to make it all work.
* == Sample to show a Parent BO configured to use a String lookup and work with related Child Records
Local loSrHead AS ‘cSrHead’
Set ClassLib To MyMainLibrary Additive
Set ClassLib To MyBoLibrary Additive && Include your Business Object ClassLibrary
loSrHead = CreateObject(‘MyInvoiceBoClass’) && A Parent class found in your BO Library VCX
*– These settings are native to the base wwBusiness operation
loSrHead.cFileName = ‘tblSrHead’ && The table name (.dbf file or Sql Server table name)
loSrHead.cAlias = ‘csrSrHead’ && Local alias name to use when opening file
loSrHead.nDataMode = 0 && Data access mode for the business object. 0 – Native Fox dbf, 2 – SQL Server
loSrHead.cPKFIeld= ‘PK’ && Points to the unique Key value column in the table. Usually an Integer column.
*– This code section is part of wwBusinessPro feature set wwBusinessPro allows for String-based lookups and related Child cursors…
loSrHead.cLookupField = ‘storeno+docno’ && This is an example of a compound string unique key lookup value.
loSrHead.cAdditionalFilter = ‘mtype = ’ && (Optional) Provides a way to further filter the record locating process.
loSrHead.cPKFIeld= ‘storeno+docno’ && Set to same value as cLookupField if no Integer PK is available in the table.
loSrHead.lLoadLineItems = .t. && Tells it load Child records when getting the Parent record.
loSrHead.lAllowEditLineItems = .t. && Tells it create a ReadWrite cursor when creating the Child record cursor
*– Setup the Child properties on the Parent
loSrHead.cLineItemsClass = ‘cSrItems’ && Child class must exist in the MyBoLibrary.vcx
loSrHead.cLineItemsAlias = ‘curSrItems’ && Cursor name where you want the Child records to be stored
*– Fetch the Parent and create a Child Cursor
loSrHead.Get(‘TWU STORE RN2009100003’) && For String lookups
loSrHead.Get(12345) && For Integer lookups
If loSrHead.lFound = .f.
*– Add any Not Found handling code here
If loSrHead.nErrorCount > 0
*– Add any Error handling code here, if not already handled in your classes.
*– Make some changes to the loSeHead.oData object and to the Child cursor
*– and save the changes…
loSrHead.Save(.t.) && .t. Tells it to save changes to the Child records also
One more thing about the Child classes…
When setting up your Child in the VCX, these are the properties you need to set on it:
cFilename (Required. Name of the dbf or Sql Server table)
cAlias (Optional. Will use cFilename by default)
cPKField (Must be an Integer. See “Important Note” below)
cFKField (Must be an Integer. Maps to Parents PK field)
cLookupField (Optional. Maps to Parents cLookupField. Use when Parent uses for String lookups)
cOrderFld (Optional. Can be used to set the ordering of child records. i.e. a sequnce field)
These properties provide the info needed by the LoadLineItems() method work out of the box.
Sometimes you may want to overwrite the LoadLineItems() method with custom code, but the default
should work in basic configurations.
In order to save changes on the Child records, they need a unique PK that can be used. See cPKField.
String cLookupField works fine to load the records in, but it does not guarantee uniqueness when
trying to save changes back.
Again, you can use cLookupField Stings for loading the records, but you must have Integer PKs
on your Child records to allow saving changes back.