Adding a link object
(Automatically adding template at the end of the page.)
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<message>Write the content here to display this box</message>
Often, when you add to an association with a link class, you want to do things with the created link object.
Often, when you add to an association with a link class, you want to do things with the created link object.


Line 8: Line 9:
  self.Flights.add(aFlight);  
  self.Flights.add(aFlight);  
  self.Bookings->select(b | b.Flight = aFlight)->first
  self.Bookings->select(b | b.Flight = aFlight)->first
There is an operator [[OCLOperators addReturnIndexOf0|addReturnIndexOf0]] that adds the Flight - and returns the zero based index of Booking.
There is an operator [[Documentation:OCLOperators addReturnIndexOf0|addReturnIndexOf0]] that adds the Flight - and returns the zero based index of Booking.
  self.Bookings.at0(self.Flights.addReturnIndexOf0(aFlight)).AttributeOnBooking
  self.Bookings.at0(self.Flights.addReturnIndexOf0(aFlight)).AttributeOnBooking


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


See also: [[Training:Association classes|Association classes]]
'''See also:''' [[Training:Association classes|Association classes]]
[[Category:UML]]
[[Category:UML]]
{{Edited|July|12|2024}}
{{Edited|July|12|2025}}

Latest revision as of 05:16, 10 February 2025

This page was created by Lars.olofsson@mdriven.net on 2018-10-18. Last edited by Stephanie@mdriven.net on 2025-02-10.

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

Do this:

Association object.png

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 addReturnIndexOf0 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.

Linkrolename.png

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

See also: Association classes