| | 14 | <$if Attribute.name == position_$> |
|---|
| | 15 | // position_ is a calculated value: @max(position_)+1. Calculate it the first time it's used. |
|---|
| | 16 | if (!result || [result longLongValue] == -1) { |
|---|
| | 17 | NSFetchRequest *fetchObjectWithMaximumPosition = [[[NSFetchRequest alloc] init] autorelease]; |
|---|
| | 18 | [fetchObjectWithMaximumPosition setEntity:[self entity]]; |
|---|
| | 19 | [fetchObjectWithMaximumPosition setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"position_" ascending:NO] autorelease]]]; |
|---|
| | 20 | [fetchObjectWithMaximumPosition setFetchLimit:1]; |
|---|
| | 21 | NSArray *objectWithMaximumPosition = [[self managedObjectContext] executeFetchRequest:fetchObjectWithMaximumPosition error:nil]; |
|---|
| | 22 | assert(objectWithMaximumPosition && [objectWithMaximumPosition count] < 2); |
|---|
| | 23 | result = [NSNumber numberWithLongLong:[objectWithMaximumPosition count] ? [[[objectWithMaximumPosition lastObject] valueForKey:@"position_"] longLongValue]+1 : 0]; |
|---|
| | 24 | [self setPosition_:result]; |
|---|
| | 25 | } |
|---|
| | 26 | <$endif$> |
|---|