views:

84

answers:

1

Hi all,

I'm programming an app for an restaurant and want to show the restaurants menu in a sectioned table view. Above the table view I've got a UISegmentedControl which controls which Menu Section to display (Food or wine). The table should show the dishes separated by sections (pe. starters, meat, etc).

I've got 3 related entities MenuSections, MenuSubsections and MenuItems which are updated from a server (items change frequently) so I wanted to display the saved data and reload if the background process has downloaded any changes.

So far so good, but now I'm facing some problems when trying to retrieve the data.

  • When initializing the controller I need to define "sectionNameKeyPath" which is in MenuSections.menuSubsection.name, but I get an error saying "to-many key not allowed here".
  • I would like to sort both MenuSubsections and MenuItems, but again an error "to-many key not allowed here".

Can anyone shed some light on this as I were not able to find any info :-(

Thanks in advance, Miguel

UPDATE:
Items created in XCDataModel:

MenuSections: 
id (int16)
name (string)
modified (date)
menuSubsections (relation to-many with MenuSubsections)

MenuSubsections:
id (int16)
name (string)
modified (date)
menuSections (relation to-one with MenuSections)
menuItems (relation to-many with MenuItems)

MenuItems:
name (string)
modified (date)
price (decimal)
menuSubsections (relation to-one with MenuSubsections)
A: 

You can't have a to-many relationship in a section name key path because the fetched results controller has no idea which of the many attribute values goes with which section title.

Suppose each MenuSections object has a relationship with 10 MenuSubsections objects each of which in turn has a relationship with 10 MenuItems objects. That is 100 MenuItems.name attributes to choose from. Which one should the controller select for which section?

You need two tables here. The first displays MenuSections objects and uses MenuSections.name as the section name key path. The rows are each MenuSections' related MenuSubsections objects. Selecting a row should push a detail table showing that row's particular MenuSubsections object's related MenuItems.

BTW, by convention, entity names are singular. So MenuSection, MenuSubsection and MenuItem. Entities are like class definitions. There is only one of them just as there are many NSString objects but only one NSString class so we don't name the class NSStrings. The name should reflect the singular nature. Plurals should be researved for to-many relationship names.

TechZen
Thanks TechZen, I don't like the idea of having to tap to show details of section and prefer to show one table containing all data sectioned. Finally, I will discard NSFRC and load the data into a Dictionary.
Michi
On the iPhone, users will expect a hierarchical UI because most apps use it. Of course, it's not required but unless you have significant reason not to use it you problem should. If you do use the all in one design, I suggest you test it thoroughly. There is surprisingly little screen area and that makes outline like views hard to interpret.
TechZen