Adding a link object
No edit summary
No edit summary
Line 1: Line 1:
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.


Do like this:
Do this:


[[File:Association_object.png|719x719px|border]]
[[File:Association_object.png|719x719px|border]]


Add a method to either of the "main" classes with content similar to this;
Add a method to either of the "main" classes with content similar to this:
  self.Flights.add(aFlight);  
  self.Flights.add(aFlight);  
  self.Bookings->select(b | b.Flight = aFlight)->first
  self.Bookings->select(b | b.Flight = aFlight)->first
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.
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 very good to set the names on the links, both the InnerLinkName and the LinkRoleName.
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 '''Persons''' end of the association.
In this example: this is the InnerLinkName and the LinkRoleName for the '''Person'''<nowiki/>'s end of the association.
[[File:Linkrolename.png|none|frame]]
[[File:Linkrolename.png|none|frame]]



Revision as of 08:12, 7 June 2023

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

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

This page was edited 87 days ago on 02/10/2024. What links here