Welcome, Guest
Username Password: Remember me
  • Page:
  • 1

TOPIC: Entity order

Entity order 1 year, 2 months ago #1

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.

Re: Entity order 1 year, 2 months ago #2

Hi Oscar,


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.


That's the correct behavior. Initially, the order property contains the order of the items at creation. When you re-arrange the cells, the order property changes to reflect the new order, which in turn gets persisted. Please tell me if I am missing something here.


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 am not able to replicate this at all. Are you able to send me your project again at our support email? Thank you very much.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
  • Page:
  • 1
Time to create page: 1.62 seconds