I have two questions about order.
I have this code for a Category entity where I want categories to be ordered by the order property. For some reason though they're ordered by creation.
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:nil action:nil];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
NSManagedObjectContext *managedObjectContext = [(SimpleExpensesAppDelegate *)[UIApplication sharedApplication].delegate
managedObjectContext];
SCClassDefinition *categoryDef = [SCClassDefinition definitionWithEntityName:@"Category"
withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"name", nil]];
categoryDef.keyPropertyName = @"order";
categoryDef.orderAttributeName = @"order";
// Validate name
SCPropertyDefinition *namePropertyDef = [categoryDef propertyDefinitionWithName:@"name"];
namePropertyDef.required = YES;
tableModel = [[SCTableViewModel alloc] initWithTableView:self.tableView withViewController:self];
SCArrayOfObjectsSection *categoriesSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil
withEntityClassDefinition:categoryDef];
categoriesSection.addButtonItem = self.navigationItem.rightBarButtonItem;
[tableModel addSection:categoriesSection];
}
I'm not sure what's wrong.
The second question is abut setting ascending ordering. In another table view I have the following code:
SCClassDefinition *expenseDef = [SCClassDefinition definitionWithEntityName:@"Expense"
withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"amount", @"category", @"created_at", nil]];
expenseDef.keyPropertyName = @"created_at";
// Category
SCClassDefinition *categoryDef = [SCClassDefinition definitionWithEntityName:@"Category"
withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"name", nil]];
categoryDef.keyPropertyName = @"order";
SCPropertyDefinition *categoryPropertyDef = [expenseDef propertyDefinitionWithName:@"category"];
categoryPropertyDef.type = SCPropertyTypeObjectSelection;
categoryPropertyDef.attributes = [SCObjectSelectionAttributes attributesWithItemsEntityClassDefinition:categoryDef
withItemsTitlePropertyName:@"name"
allowMultipleSelection:NO
allowNoSelection:YES];
tableModel = [[SCTableViewModel alloc] initWithTableView:self.tableView withViewController:self];
SCArrayOfObjectsSection *expensesSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil
withEntityClassDefinition:expenseDef];
//expensesSection.sortItemsSetAscending = FALSE;
expensesSection.addButtonItem = self.navigationItem.rightBarButtonItem;
[tableModel addSection:expensesSection];
If I uncomment sortItemsSetAscending then no records are displayed and when I try to add an Item the application crashes saying that the number of rows returned are incorrect. I'm using STV 2.0 rC2.
By the way, you can see that I have a categories relationship in this second example, and here it's sorted correctly according to the order attribute.