Skip to content
Permalink
Browse files
better be safe than sorry
  • Loading branch information
3nids committed Nov 8, 2021
1 parent 1f8b3e5 commit ac2df242c0dc0c72ec8b93acdb13fd6e2df49d70
Showing with 18 additions and 4 deletions.
  1. +18 −4 src/core/qgsrelation.cpp
@@ -222,8 +222,15 @@ QString QgsRelation::getRelatedFeaturesFilter( const QgsFeature &feature ) const
{
QVariant val( feature.attribute( pair.referencedField() ) );
int referencingIdx = referencingLayer()->fields().lookupField( pair.referencingField() );
QVariant::Type fieldType = referencingLayer()->fields().at( referencingIdx ).type();
conditions << QgsExpression::createFieldEqualityExpression( pair.referencingField(), val, fieldType );
if ( referencingIdx >= 0 )
{
QVariant::Type fieldType = referencingLayer()->fields().at( referencingIdx ).type();
conditions << QgsExpression::createFieldEqualityExpression( pair.referencingField(), val, fieldType );
}
else
{
conditions << QgsExpression::createFieldEqualityExpression( pair.referencingField(), val );
}
}

return conditions.join( QLatin1String( " AND " ) );
@@ -236,9 +243,16 @@ 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 ), fieldType );
if ( referencedIdx >= 0 )
{
QVariant::Type fieldType = referencedLayer()->fields().at( referencedIdx ).type();
conditions << QgsExpression::createFieldEqualityExpression( pair.referencedField(), attributes.at( referencingIdx ), fieldType );
}
else
{
conditions << QgsExpression::createFieldEqualityExpression( pair.referencedField(), attributes.at( referencingIdx ) );
}
}

QgsFeatureRequest myRequest;

0 comments on commit ac2df24

Please sign in to comment.