When the same method for edges enumeration is used inside its block, wrong data can get to enumeration cycle.
For example, the following code demonstrates incorrect behaviour: inner enumeration for edge with name EdgeCommandsToPlayers has Commands as destination collection (should be Players).
[[transaction relationshipExtension] enumerateEdgesWithName:EdgeCategoriesToCommands
sourceKey:category.key
collection:Categories
usingBlock:^(YapDatabaseRelationshipEdge* edge, BOOL* stop)
{
Command* command = [transaction objectForKey:edge.destinationKey inCollection:Commands];
NSInteger __block sumScore = 0;
[[transaction relationshipExtension] enumerateEdgesWithName:EdgeCommandsToPlayers
sourceKey:command.key
collection:Commands
usingBlock:^(YapDatabaseRelationshipEdge* edge1, BOOL* stop1)
{
Player* player = [transaction objectForKey:edge1.destinationKey inCollection:edge1.destinationCollection];
sumScore += [player.score intValue];
}
}];
command.score = sumScore;
[commands addObject:command];
}];
Probably, it happens because Statement in such case is shared and is not properly cleared.
So, is it bug or "enumerate inside enumerate" pattern just shouldn't be used?
When the same method for edges enumeration is used inside its block, wrong data can get to enumeration cycle.
For example, the following code demonstrates incorrect behaviour: inner enumeration for edge with name EdgeCommandsToPlayers has Commands as destination collection (should be Players).
Probably, it happens because Statement in such case is shared and is not properly cleared.
So, is it bug or "enumerate inside enumerate" pattern just shouldn't be used?