Re: Initiating a To-many entity
Re: Initiating a To-many entity
- Subject: Re: Initiating a To-many entity
- From: Quincey Morris <email@hidden>
- Date: Thu, 16 Jul 2009 22:36:11 -0700
On Jul 16, 2009, at 07:28, Sean Kline wrote:
Imagine the following example:
Entity Attributes Relationships
WeeklyMenu date menuItems (To-many
Destination: MenuItems)
MenuItems dish week (Destination: WeeklyMenu)
chef
cost
Category chef
dish
Chef Dish
LunchChef BLT
LunchChef Soup
DinnerChef Soup
DinnerChef Salad
DinnerChef Steak
When a new date is created, I want MenuItems to automatically have
records
corresponding to all of the categories. How would you do this? The
example
is a bit contrived but is analogous to my actual application. The
idea is
to have the same categories every week with varying prices. Feel
free to
suggest a different model if mine is not appropriate. I am able to
construct
an interface which allows for new dates and displays the pre-populated
categories, but I am having difficulty figuring out how to create the
MenuItems automatically.
(I compressed blank lines from your example for brevity.)
Since you always want to add menu items for the same set of
categories, it's easiest to implement an override of awakeFromInsert:,
then create them and set their week relationship in there.
Note that your MenuItems entity should really be called MenuItem,
since there's a different instance for each chef/dish combination
(assuming I'm reading your example right.) Typically, it's correct for
a to-many relationship to be plural and the related-to entity to be
singular.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden