codeable_models.add_links¶
-
codeable_models.
add_links
(link_definitions, **kwargs)¶ Function used to add multiple links at once, maybe to different source objects. The function takes a dict of link definitions. With it multiple links can be specified at once. It also supports association and role name specifications in the keyword args. If those are used, only one kind of link can be specified with one
add_links()
call.For example, we can use this function to define the links between items and their carts:
new_links = add_links({cart1: [item1, item2], cart2: [item3, item4, item5]}, role_name="item in cart")
The values in the link definitions dict can either be a single object or a list. A list is needed for defining links to more than one object. The keys of the link definition must be single objects. As a dict can take in a key only once, each object might appear only once as a key.
association
orrole_name
keyword args can be used to specify the association and/or association direction for the links to be created. If neitherassociation
norrole_name
are specified, the association is guessed based on the source and target objects in the link definitions. If association and/or role name are used, the correct association and/or association direction can be selected unambiguously.- Parameters
link_definitions (dict) – A dict of link definitions as explained before.
**kwargs –
The following keyword arguments are supported:
association
:Specify the association to be used as a link classifier for all the links added with this
add_links
invocation. Please note that association (alone) can be ambiguous, as a recursive association from an class to itself has two possible link directions for the combination of association and source/target objects of the same type.
role_name
:Specify the association and its direction by role name to be used as a link classifier for all the links added with this
add_links
invocation. Please note that role name alone can be ambiguous, as multiple same-named role names could exist in different associations of a class (and its superclasses).
stereotype_instances
:Used to set the stereotype instances for the links, using a stereotype or a list of stereotypes as in the
stereotype_instances
setter ofCLink
.
tagged_values
:Used to set the tagged values for the links, using a values dict as in the
tagged_values
setter ofCLink
.
- Returns
List of newly created links.
- Return type
List[CLink]