Skip to content
Permalink
Browse files
fix getReferencedFeature for relation with mismathcing types in field…
… pair
  • Loading branch information
3nids committed Nov 8, 2021
1 parent 4b3c50d commit 1f8b3e5d41911ef7da08c97a85c96a9adf334bcc
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/core/qgsrelation.cpp
@@ -221,7 +221,9 @@ QString QgsRelation::getRelatedFeaturesFilter( const QgsFeature &feature ) const
for ( const FieldPair &pair : std::as_const( d->mFieldPairs ) )
{
QVariant val( feature.attribute( pair.referencedField() ) );
conditions << QgsExpression::createFieldEqualityExpression( pair.referencingField(), val );
int referencingIdx = referencingLayer()->fields().lookupField( pair.referencingField() );
QVariant::Type fieldType = referencingLayer()->fields().at( referencingIdx ).type();
conditions << QgsExpression::createFieldEqualityExpression( pair.referencingField(), val, fieldType );
}

return conditions.join( QLatin1String( " AND " ) );
@@ -233,8 +235,10 @@ QgsFeatureRequest QgsRelation::getReferencedFeatureRequest( const QgsAttributes

for ( const FieldPair &pair : std::as_const( d->mFieldPairs ) )
{
int referencedIdx = referencedLayer()->fields().lookupField( pair.referencedField() );
QVariant::Type fieldType = referencedLayer()->fields().at( referencedIdx ).type();
int referencingIdx = referencingLayer()->fields().lookupField( pair.referencingField() );
conditions << QgsExpression::createFieldEqualityExpression( pair.referencedField(), attributes.at( referencingIdx ) );
conditions << QgsExpression::createFieldEqualityExpression( pair.referencedField(), attributes.at( referencingIdx ), fieldType );
}

QgsFeatureRequest myRequest;

0 comments on commit 1f8b3e5

Please sign in to comment.