Class: QgsWeakRelation

class qgis.core.QgsWeakRelation

Bases: sip.wrapper

The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields.

This class is used to store relation information attached to a layer style, a method to attempt relation resolution is also implemented and can be used to create a QgsRelation after the dependent layers are loaded and available.

In constrast to QgsRelation, QgsWeakRelation can be used to encapsulate information about a relationship which does not currently exist in a QGIS project. E.g. it can be used to represent a relationship which exists in a database backend (but not within a QGIS project). Accordingly, some properties available in QgsWeakRelation are included for informational purposes only, and cannot be translated to QgsRelations or respected in QGIS relationships.

New in version 3.12.

QgsWeakRelation() Default constructor for an invalid relation.

QgsWeakRelation(QgsWeakRelation)

Methods

backwardPathLabel

Returns the label of the backward path for the relationship.

cardinality

Returns the relationship's cardinality.

forwardPathLabel

Returns the label of the forward path for the relationship.

id

Returns the relationship's ID.

mappingReferencedLayerFields

Returns the list of fields from the mappingTable() involved in the relationship.

mappingReferencingLayerFields

Returns the list of fields from the mappingTable() involved in the relationship.

mappingTableName

Returns the layer name of the mapping table, which forms the middle table in many-to-many relationships.

mappingTableProvider

Returns the provider ID for the mapping table, which forms the middle table in many-to-many relationships.

mappingTableSource

Returns the source URI for the mapping table, which forms the middle table in many-to-many relationships.

name

Returns the relationship's name.

readXml

Returns a weak relation for the given layer.

referencedLayerFields

Returns the list of fields from the referencedLayer() involved in the relationship.

referencedLayerName

Returns the layer name of the referenced (or "parent" / "left") layer.

referencedLayerProvider

Returns the provider ID for the referenced (or "parent" / "left") layer.

referencedLayerSource

Returns the source URI for the referenced (or "parent" / "left") layer.

referencingLayerFields

Returns the list of fields from the referencingLayer() involved in the relationship.

referencingLayerName

Returns the layer name of the referencing (or "child" / "right") layer.

referencingLayerProvider

Returns the provider ID for the referencing (or "child" / "right") layer.

referencingLayerSource

Returns the source URI for the referencing (or "child" / "right") layer.

relatedTableType

Returns the type string of the related table.

resolvedRelations

Resolves a weak relation in the given project returning a list of possibly invalid QgsRelations and without performing any kind of validity check.

setBackwardPathLabel

Sets the label of the backward path for the relationship.

setCardinality

Sets the relationship's cardinality.

setForwardPathLabel

Sets the label of the forward path for the relationship.

setMappingReferencedLayerFields

Sets the list of fields from the mappingTable() involved in the relationship.

setMappingReferencingLayerFields

Sets the list of fields from the mappingTable() involved in the relationship.

setReferencedLayerFields

Sets the list of fields from the referencedLayer() involved in the relationship.

setReferencingLayerFields

Sets the list of fields from the referencingLayer() involved in the relationship.

setRelatedTableType

Sets the type string of the related table.

strength

Returns the strength of the relation.

writeXml

Writes a weak relation infoto an XML structure.

Attributes

Referenced

Referencing

Referenced = 1
Referencing = 0
class WeakRelationType

Bases: int

backwardPathLabel(self) str

Returns the label of the backward path for the relationship.

The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.

E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be “contains” and the backward path label could be “is located within”. A client could then generate a user friendly description string such as “fire hose 1234 is located within building 15a”.

New in version 3.28.

Return type:

str

cardinality(self) Qgis.RelationshipCardinality

Returns the relationship’s cardinality.

See also

setCardinality()

New in version 3.28.

Return type:

Qgis.RelationshipCardinality

forwardPathLabel(self) str

Returns the label of the forward path for the relationship.

The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.

E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be “contains” and the backward path label could be “is located within”. A client could then generate a user friendly description string such as “fire hose 1234 is located within building 15a”.

New in version 3.28.

Return type:

str

id(self) str

Returns the relationship’s ID.

New in version 3.28.

Return type:

str

mappingReferencedLayerFields(self) List[str]

Returns the list of fields from the mappingTable() involved in the relationship.

These fields will be matched to the referencedLayerFields() in many-to-many joins.

New in version 3.28.

Return type:

List[str]

mappingReferencingLayerFields(self) List[str]

Returns the list of fields from the mappingTable() involved in the relationship.

These fields will be matched to the referencingLayerFields() in many-to-many joins.

New in version 3.28.

Return type:

List[str]

mappingTableName(self) str

Returns the layer name of the mapping table, which forms the middle table in many-to-many relationships.

Note

the layer name refers to the layer name used in the datasource, not in any associated QgsVectorLayer.

New in version 3.28.

Return type:

str

mappingTableProvider(self) str

Returns the provider ID for the mapping table, which forms the middle table in many-to-many relationships.

New in version 3.28.

Return type:

str

mappingTableSource(self) str

Returns the source URI for the mapping table, which forms the middle table in many-to-many relationships.

New in version 3.28.

Return type:

str

name(self) str

Returns the relationship’s name.

New in version 3.28.

Return type:

str

readXml(layer: QgsVectorLayer, type: QgsWeakRelation.WeakRelationType, node: QDomNode, resolver: QgsPathResolver) QgsWeakRelation

Returns a weak relation for the given layer.

Parameters:

New in version 3.16.

Return type:

QgsWeakRelation

referencedLayerFields(self) List[str]

Returns the list of fields from the referencedLayer() involved in the relationship.

New in version 3.28.

Return type:

List[str]

referencedLayerName(self) str

Returns the layer name of the referenced (or “parent” / “left”) layer.

Note

the layer name refers to the layer name used in the datasource, not in any associated QgsVectorLayer.

New in version 3.28.

Return type:

str

referencedLayerProvider(self) str

Returns the provider ID for the referenced (or “parent” / “left”) layer.

New in version 3.28.

Return type:

str

referencedLayerSource(self) str

Returns the source URI for the referenced (or “parent” / “left”) layer.

New in version 3.28.

Return type:

str

referencingLayerFields(self) List[str]

Returns the list of fields from the referencingLayer() involved in the relationship.

New in version 3.28.

Return type:

List[str]

referencingLayerName(self) str

Returns the layer name of the referencing (or “child” / “right”) layer.

Note

the layer name refers to the layer name used in the datasource, not in any associated QgsVectorLayer.

New in version 3.28.

Return type:

str

referencingLayerProvider(self) str

Returns the provider ID for the referencing (or “child” / “right”) layer.

New in version 3.28.

Return type:

str

referencingLayerSource(self) str

Returns the source URI for the referencing (or “child” / “right”) layer.

New in version 3.28.

Return type:

str

relatedTableType(self) str

Returns the type string of the related table.

This a free-form string representing the type of related features, where the exact interpretation is format dependent. For instance, table types from GeoPackage relationships will directly reflect the categories from the GeoPackage related tables extension (i.e. “media”, “simple attributes”, “features”, “attributes” and “tiles”).

New in version 3.28.

Return type:

str

resolvedRelations(self, project: QgsProject) List[QgsRelation]

Resolves a weak relation in the given project returning a list of possibly invalid QgsRelations and without performing any kind of validity check.

Note

Client code should never assume that the returned relations are valid and the layer components are not NULL.

Parameters:

project (QgsProject) –

Return type:

List[QgsRelation]

setBackwardPathLabel(self, label: str)

Sets the label of the backward path for the relationship.

The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.

E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be “contains” and the backward path label could be “is located within”. A client could then generate a user friendly description string such as “fire hose 1234 is located within building 15a”.

New in version 3.28.

Parameters:

label (str) –

setCardinality(self, cardinality: Qgis.RelationshipCardinality)

Sets the relationship’s cardinality.

See also

cardinality()

New in version 3.28.

Parameters:

cardinality (Qgis.RelationshipCardinality) –

setForwardPathLabel(self, label: str)

Sets the label of the forward path for the relationship.

The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.

E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be “contains” and the backward path label could be “is located within”. A client could then generate a user friendly description string such as “fire hose 1234 is located within building 15a”.

New in version 3.28.

Parameters:

label (str) –

setMappingReferencedLayerFields(self, fields: Iterable[str])

Sets the list of fields from the mappingTable() involved in the relationship.

These fields will be matched to the referencedLayerFields() in many-to-many joins.

New in version 3.28.

Parameters:

fields (Iterable[str]) –

setMappingReferencingLayerFields(self, fields: Iterable[str])

Sets the list of fields from the mappingTable() involved in the relationship.

These fields will be matched to the referencingLayerFields() in many-to-many joins.

New in version 3.28.

Parameters:

fields (Iterable[str]) –

setReferencedLayerFields(self, fields: Iterable[str])

Sets the list of fields from the referencedLayer() involved in the relationship.

New in version 3.28.

Parameters:

fields (Iterable[str]) –

setReferencingLayerFields(self, fields: Iterable[str])

Sets the list of fields from the referencingLayer() involved in the relationship.

New in version 3.28.

Parameters:

fields (Iterable[str]) –

setRelatedTableType(self, type: str)

Sets the type string of the related table.

This a free-form string representing the type of related features, where the exact interpretation is format dependent. For instance, table types from GeoPackage relationships will directly reflect the categories from the GeoPackage related tables extension (i.e. “media”, “simple attributes”, “features”, “attributes” and “tiles”).

New in version 3.28.

Parameters:

type (str) –

strength(self) Qgis.RelationshipStrength

Returns the strength of the relation.

Return type:

Qgis.RelationshipStrength

writeXml(layer: QgsVectorLayer, type: QgsWeakRelation.WeakRelationType, relation: QgsRelation, node: QDomNode, doc: QDomDocument)

Writes a weak relation infoto an XML structure. Used for saving .qgs projects

Parameters:
  • layer (QgsVectorLayer) – the layer which we save the weak relation for

  • type (QgsWeakRelation.WeakRelationType) – determines if the layer is referencing or referenced

  • relation (QgsRelation) – the relation to save as a weak relation

  • node (QDomNode) – The parent node in which the relation will be created

  • doc (QDomDocument) – The document in which the relation will be saved

New in version 3.16.