gws.plugin.model_field.related_linked_feature_list

Related linked feature list field.

Represents an M:N relationship between two models via a link table (“associative entity”):

+------------+         +-------------------------------+         +-----------+
| this model |         | linkTableName                 |         | toModel   |
+------------+         +-------------------------------+         +-----------+
| fromColumn |-------<<| linkFromColumn   linkToColumn |>>-------| toColumn  |
+------------+         +-------------------------------+         +-----------+

The value of the field is the list of linked features of the related model. fromColumn and toColumn default to the primary keys. The link table must be in the same database as this model.

When a feature is written, the rows of the link table are synchronized with the field value: missing links are inserted, links to features no longer in the list are deleted. The linked features themselves are not changed. When a related feature is created together with features of this model, links to them are inserted. Without a configured widget, the field uses a featureList widget.

Example:

fields+ {
    name "tags"
    type "relatedLinkedFeatureList"
    toModel "model_tag"
    linkTableName "edit.poi_tag"
    linkFromColumn "poi_id"
    linkToColumn "tag_id"
}

Source code: gws.plugin.model_field.related_linked_feature_list

Package Contents

class gws.plugin.model_field.related_linked_feature_list.Config

Bases: gws.base.model.related_field.Config

Field listing features of another model, related via a link table.

fromColumn: str = ''

Key column in this table, primary key by default.

linkFromColumn: str

Column in the link table that refers to this model.

linkTableName: str

Link table name.

linkToColumn: str

Column in the link table that refers to the related model.

toColumn: str = ''

Key column in the related table, primary key by default.

toModel: str

UID of the related model.

class gws.plugin.model_field.related_linked_feature_list.Object

Bases: gws.base.model.related_field.Object

Related linked feature list field object.

attributeType
after_create(feature, mc)
after_select(features, mc)
after_update(feature, mc)
after_write(feature, key, mc: gws.ModelContext)

Synchronize the link table with the field value of a written feature.

Does nothing if the user may not write the field or the maximum relation depth is reached.

Parameters:
  • feature – The created or updated feature.

  • key – Value of the key column of the feature.

  • mc – The model context.

configure_relationship()

Insert links into the link table.

Parameters:
  • links – (src_key, dst_key) tuples.

  • mc – The model context.

Delete links from the link table.

Parameters:
  • links – (src_key, dst_key) tuples.

  • mc – The model context.

Read the links of the given keys from the link table.

Parameters:
  • left_keys – Key values of features of this model.

  • mc – The model context.

Returns:

A set of (src_key, dst_key) tuples.

class gws.plugin.model_field.related_linked_feature_list.Props

Bases: gws.base.model.related_field.Props