Skip to content

Commit

Permalink
Generated QgsRelations now support getting the related features
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Jan 12, 2021
1 parent 89c07ff commit 53ca67a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/core/qgsrelation.cpp
Expand Up @@ -21,6 +21,8 @@
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsrelation_p.h"
#include "qgspolymorphicrelation.h"
#include "qgsrelationmanager.h"

QgsRelation::QgsRelation()
: d( new QgsRelationPrivate() )
Expand Down Expand Up @@ -202,6 +204,21 @@ QString QgsRelation::getRelatedFeaturesFilter( const QgsFeature &feature ) const
{
QStringList conditions;

if ( ! d->mPolymorphicRelationId.isEmpty() )
{
QgsPolymorphicRelation polymorphicRelation = QgsProject::instance()->relationManager()->polymorphicRelation( d->mPolymorphicRelationId );

if ( polymorphicRelation.isValid() )
{
conditions << QgsExpression::createFieldEqualityExpression( polymorphicRelation.referencedLayerField(), polymorphicRelation.layerRepresentation( referencedLayer() ) );
}
else
{
QgsDebugMsg( "The polymorphic relation is invalid" );
conditions << QStringLiteral( " FALSE " );
}
}

for ( const FieldPair &pair : qgis::as_const( d->mFieldPairs ) )
{
QVariant val( feature.attribute( pair.referencedField() ) );
Expand Down

0 comments on commit 53ca67a

Please sign in to comment.