🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Parsed/Adding a link object
This page was created by PageReplicator on 2025-09-01. Last edited by PageReplicator on 2025-09-01.

Template:Notice



Often, when you add to an association with a link class, you want to do things with the created link object.

Do this:

<a href="/File:Association_object.png" class="image" data-bs-title="File:Association_object.png" data-bs-filetimestamp="20181022081429"><img alt="Association object.png" src="/images/d/da/Association_object.png" decoding="async" width="719" height="294" class="thumbborder" /></a>

Add a method to either of the "main" classes with content similar to this:

self.Flights.add(aFlight); 
self.Bookings->select(b | b.Flight = aFlight)->first

There is an operator <a href="/Documentation:OCLOperators_addReturnIndexOf0" title="Documentation:OCLOperators addReturnIndexOf0" data-bs-title="Documentation:OCLOperators_addReturnIndexOf0">addReturnIndexOf0</a> that adds the Flight - and returns the zero based index of Booking.

self.Bookings.at0(self.Flights.addReturnIndexOf0(aFlight)).AttributeOnBooking

It adds the object at the other end to the association and looks up the created link object - in this case, a Booking object and returns it.

Please note that it's usually good to set the names on the links, both the InnerLinkName and the LinkRoleName.

In this example: this is the InnerLinkName and the LinkRoleName for the Person's end of the association.

<a href="/File:Linkrolename.png" class="image" data-bs-title="File:Linkrolename.png" data-bs-filetimestamp="20181018141210"><img alt="Linkrolename.png" src="/images/2/2b/Linkrolename.png" decoding="async" width="478" height="51" class="thumbimage" /></a>

Note! From the Booking object, it's only one Person object in the association. Hence, Person, not Persons

See also: <a href="/Training:Association_classes" title="Training:Association classes" data-bs-title="Training:Association_classes">Association classes</a>