Skip to content

Commit

Permalink
prevent NPE when baseKeyPath is null and therefore no relationship is…
Browse files Browse the repository at this point in the history
… found
  • Loading branch information
nur-sgaertner authored and darkv committed Sep 21, 2015
1 parent 4c279cc commit 56ff724
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public String sqlStringForSQLExpression(EOQualifier qualifier, EOSQLExpression e
}

String srcEntityForeignKey = null;
NSArray<EOAttribute> sourceAttributes = relationship.sourceAttributes();
NSArray<EOAttribute> sourceAttributes = relationship != null ? relationship.sourceAttributes() : null;
if (sourceAttributes != null && sourceAttributes.count() > 0) {
EOAttribute fk = sourceAttributes.lastObject();
srcEntityForeignKey = expression.sqlStringForAttribute(fk);
Expand All @@ -259,8 +259,14 @@ public String sqlStringForSQLExpression(EOQualifier qualifier, EOSQLExpression e
srcEntityForeignKey = expression.sqlStringForAttribute(pk);
}

EOJoin parentChildJoin = ERXArrayUtilities.firstObject(relationship.joins());
String destEntityForeignKey = "." + expression.sqlStringForSchemaObjectName(parentChildJoin.destinationAttribute().columnName());
String destEntityForeignKey;
if (relationship != null) {
EOJoin parentChildJoin = ERXArrayUtilities.firstObject(relationship.joins());
destEntityForeignKey = "." + expression.sqlStringForSchemaObjectName(parentChildJoin.destinationAttribute().columnName());
} else {
EOAttribute pk = srcEntity.primaryKeyAttributes().lastObject();
destEntityForeignKey = "." + expression.sqlStringForSchemaObjectName(pk.columnName());
}

EOQualifier qual = EOQualifierSQLGeneration.Support._schemaBasedQualifierWithRootEntity(subqualifier, destEntity);
EOFetchSpecification fetchSpecification = new EOFetchSpecification(destEntity.name(), qual, null, false, true, null);
Expand Down

0 comments on commit 56ff724

Please sign in to comment.