" *****************************************************************************************************
*
* rel.txt
*
*   This examples shows how to define a relationship in a model
*
*
******************************************************************************************************"

| aModel aTextDisplay sectionType courseType attributesDict courseSections |
aTextDisplay := TextWindow  windowLabeled: 'LPC Brokers - creating a relationship'
                           frame: (0 @ 0 corner: 500 @ 500).
aTextDisplay cr. 
 
" let's get our model"
aModel := LPCModel getName: #LpcSample.
 
"Define the section type"
sectionType := LPCObjectType 
    createNewFromDbName: #Section 
            table: (Array with:'Section' with: nil with: nil)
            fields: #( (nil nil 'Section' 'COURSE' 1) 
                           (nil nil 'Section' 'SECTION' 4)
                           (nil nil 'Section' 'EMPNUM' 4) )
            keys: #( (nil nil nil 'Course') (nil nil nil 'Section') ).
  
" let's add this type to the model"
aModel addType: sectionType.

"let's retrieve our Course type"
courseType := aModel typeNamed: #Course.

"let's define the relationship"
courseSections := LPCObjectTypeRelationship new: #OrderedCollection
    objectType: courseType 
    relatedWith: sectionType 
    matching: ((Dictionary new) at: 'course'  put: 'course'; yourself ).

"add the attribute for the relationship to the course type"
courseType addAttribute: 'sections'.

"add the relationship now to the course type attribure Sections"
courseType addRelationship: courseSections  forAttribute: 'sections'.

"let's display the relationship"
aTextDisplay nextPutAll: 'Course/Section Relationship' ; cr.
aTextDisplay nextPutAll: 'a ' , courseSections objectType typeName asString ;
                       nextPutAll: ' is related to an ' ;
                       nextPutAll:  courseSections relationshipType asString , ' of ' ;
                       nextPutAll:  courseSections relatedObjectType typeName asString.           
                        
                        
                                                                                     


    

 







































































































































































































































































































































































 
