Class: QgsRelation¶
-
class
qgis.core.
QgsRelation
¶ Bases:
sip.wrapper
Default constructor. Creates an invalid relation.
QgsRelation(other: QgsRelation) Copies a relation. This makes a shallow copy, relations are implicitly shared and only duplicated when the copy is changed.
Enums
Methods
Add a field pairs which is part of this relation The first element of each pair are the field names of the foreign key.
Creates a relation from an XML structure.
Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key.
Generate a (project-wide) unique id for this relation
Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.
Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.
Creates an iterator which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
Returns a filter expression which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
Creates a request to return all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
Compares the two QgsRelation, ignoring the name and the ID.
A (project-wide) unique id for this relation
Returns the validity of this relation.
Returns a human readable name for this relation.
Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer.
Access the referenced (parent) layer
Access the referenced (parent) layer’s id
Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer.
Access the referencing (child) layer This is the layer which has the field(s) which point to another layer
Access the referencing (child) layer’s id This is the layer which has the field(s) which point to another layer
Gets the referenced field counterpart given a referencing field.
Gets the referencing field counterpart given a referenced field.
Set an id for this relation
Set a name for this relation
Set the referenced (parent) layer id.
Set the referencing (child) layer id.
Set a strength for this relation
Returns the relation strength as a string
Updates the validity status of this relation.
Writes a relation to an XML structure.
Signals
Attributes
-
Association
= 0¶
-
Composition
= 1¶
-
class
RelationStrength
¶ Bases:
int
-
addFieldPair
(self, referencingField: str, referencedField: str)¶ Add a field pairs which is part of this relation The first element of each pair are the field names of the foreign key. The second element of each pair are the field names of the matching primary key.
- Parameters
referencingField – The field name on the referencing (child) layer (FK)
referencedField – The field name on the referenced (parent) layer (PK)
-
createFromXml
(node: QDomNode, context: QgsReadWriteContext) → QgsRelation¶ Creates a relation from an XML structure. Used for reading .qgs projects.
- Parameters
node – The dom node containing the relation information
context – to pass project translator
- Returns
A relation
-
fieldPairs
(self) → Dict[str, str]¶ Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key. The second element of each pair are the field names of the matching primary key.
- Returns
The fields forming the relation
-
generateId
(self)¶ Generate a (project-wide) unique id for this relation
New in version 3.0.
-
getReferencedFeature
(self, feature: QgsFeature) → QgsFeature¶ Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.
- Parameters
feature – A feature from the referencing (child) layer
- Returns
A request the referenced feature
-
getReferencedFeatureRequest
(self, attributes: object) → QgsFeatureRequest¶ Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.
- Parameters
attributes – An attribute vector containing the foreign key
- Returns
A request the referenced feature
getReferencedFeatureRequest(self, feature: QgsFeature) -> QgsFeatureRequest Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.
- Parameters
feature – A feature from the referencing (child) layer
- Returns
A request the referenced feature
-
getRelatedFeatures
(self, feature: QgsFeature) → QgsFeatureIterator¶ Creates an iterator which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
- Parameters
feature – A feature from the referenced (parent) layer
- Returns
An iterator with all the referenced features
See also
See also
-
getRelatedFeaturesFilter
(self, feature: QgsFeature) → str¶ Returns a filter expression which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
- Parameters
feature – A feature from the referenced (parent) layer
- Returns
expression filter string for all the referencing features
See also
See also
New in version 2.16.
-
getRelatedFeaturesRequest
(self, feature: QgsFeature) → QgsFeatureRequest¶ Creates a request to return all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
- Parameters
feature – A feature from the referenced (parent) layer
- Returns
A request for all the referencing features
See also
See also
-
hasEqualDefinition
(self, other: QgsRelation) → bool¶ Compares the two QgsRelation, ignoring the name and the ID.
- Parameters
other – The other relation
- Returns
True
if they are similar
New in version 3.0.
-
id
(self) → str¶ A (project-wide) unique id for this relation
- Returns
The id
-
isValid
(self) → bool¶ Returns the validity of this relation. Don’t use the information if it’s not valid. A relation is considered valid if both referenced and referencig layers are valid.
- Returns
True
if the relation is valid
-
name
(self) → str¶ Returns a human readable name for this relation. Mostly used as title for the children.
See also
- Returns
A name
-
referencedFields
(self) → List[int]¶ Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer.
- Returns
A list of attributes
-
referencedLayer
(self) → QgsVectorLayer¶ Access the referenced (parent) layer
- Returns
referenced layer
-
referencedLayerId
(self) → str¶ Access the referenced (parent) layer’s id
- Returns
The id of the referenced layer
-
referencingFields
(self) → List[int]¶ Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer.
- Returns
A list of attributes
-
referencingLayer
(self) → QgsVectorLayer¶ Access the referencing (child) layer This is the layer which has the field(s) which point to another layer
- Returns
The referencing layer
-
referencingLayerId
(self) → str¶ Access the referencing (child) layer’s id This is the layer which has the field(s) which point to another layer
- Returns
The id of the referencing layer
-
resolveReferencedField
(self, referencingField: str) → str¶ Gets the referenced field counterpart given a referencing field.
New in version 3.0.
-
resolveReferencingField
(self, referencedField: str) → str¶ Gets the referencing field counterpart given a referenced field.
New in version 3.0.
-
setId
(self, id: str)¶ Set an id for this relation
-
setName
(self, name: str)¶ Set a name for this relation
-
setReferencedLayer
(self, id: str)¶ Set the referenced (parent) layer id. This layer will be searched in the registry.
-
setReferencingLayer
(self, id: str)¶ Set the referencing (child) layer id. This layer will be searched in the registry.
-
setStrength
(self, strength: QgsRelation.RelationStrength)¶ Set a strength for this relation
New in version 3.0.
-
staticMetaObject
= <PyQt5.QtCore.QMetaObject object>¶
-
strength
(self) → QgsRelation.RelationStrength¶ Returns the relation strength as a string
- Returns
strength
New in version 3.0.
-
updateRelationStatus
(self)¶ Updates the validity status of this relation. Will be called internally whenever a member is changed.
New in version 3.6.
-
writeXml
(self, node: QDomNode, doc: QDomDocument)¶ Writes a relation to an XML structure. Used for saving .qgs projects
- Parameters
node – The parent node in which the relation will be created
doc – The document in which the relation will be saved
-