• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Addressing Relationships in awakeFromInsert
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Addressing Relationships in awakeFromInsert


  • Subject: Re: Addressing Relationships in awakeFromInsert
  • From: August Trometer <email@hidden>
  • Date: Wed, 10 Aug 2005 17:33:03 -0500

Sorry for not being clear. I guess I'm not explaining this properly, so I'll try again with more detail.

I've got 2 Entities: Show and Episode.

In my model, I've defined an inverse relationship between Show and Episode, so that a Show has a to-many relationship (called "episodes") with the Episode entity, and Epsiode has a to-one relationship (called "show") with the Show entity. The relationship from Show to Episode is optional, while the relationship from Episode to Show is not (since you can't have an Episode without a Show).

When I create a Show, everything is fine -- I can edit, update, whatever. I'm not wanting Episodes to be created when a Show is created, nor am I wanting a Show to be created when an Episode is.

In my UI, I'm using a contentSet to define what Episodes show show in my list, based on the Show that is selected. This all works fine.

So, now I add an Episode for a particular show. Because everything works up to this point -- episodes for a certain Show only appear when that particular Show is selected -- I'm assuming that the relationship does exist between Episode and Show. I want to take advantage of that when the Episodes are created. That's where awakeFromInsert comes in.

- (void) awakeFromInsert
{
    [super awakeFromInsert];

[self setValue:[NSDate date] forKey:@"dateCreated"];
[self setValue:[self valueForKeyPath:@"show.createdBy"] forKey:@"createdBy"];
}


All I want to do here is set default values in the newly created Episode based on some of the data in the Show for which the Episode was created. The user can then change this information as needed. I would expect that I could traverse the keyPath to get the Show information.

But when I try to reference the Show, I get a Null value, which strikes me as odd, since the UI is obviously handling the relationship between the two just fine.

This, I guess, leads me back to the beginning: what am I doing wrong that the relationship between the two isn't showing up during awakeFromInsert?

Thanks!

August







On Aug 10, 2005, at 4:02 PM, mmalcolm crawford wrote:


On Aug 10, 2005, at 1:31 PM, August Trometer wrote:


At no point am I setting the Master object -- this should be done automatically. I'm assuming (maybe incorrectly?) that because of the inverse Relationship set up between the Master and Detail Entities that the "master" Relationship in my Detail object automatically points back to the Master object that it's created within.


"It is important to note that simply defining a relationship does not cause a destination object to be created when a new source object is created. In this respect, defining a relationship is akin to declaring an instance variable in a standard Objective-C class. Consider the following example.


@interface Widget : NSObject
{
Sprocket *_sprocket;
}
If you create an instance of Widget, an instance of Sprocket is not created unless you write code to cause it to happen (for example, by overriding the init method). Similarly, if you define an Address entity, and a non-optional to-one relationship from Employee to Address, then simply creating an instance of Employee does not create a new Address instance. Likewise, if you define a non- optional to-many relationship from Employee to Address with a minimum count of 1, then simply creating an instance of Employee does not create a new Address instance."


mmalc




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Addressing Relationships in awakeFromInsert
      • From: Frédéric Testuz <email@hidden>
    • Re: Addressing Relationships in awakeFromInsert
      • From: mmalcolm crawford <email@hidden>
    • Re: Addressing Relationships in awakeFromInsert
      • From: Charilaos Skiadas <email@hidden>
References: 
 >Addressing Relationships in awakeFromInsert (From: August Trometer <email@hidden>)
 >Re: Addressing Relationships in awakeFromInsert (From: Jim Correia <email@hidden>)
 >Re: Addressing Relationships in awakeFromInsert (From: August Trometer <email@hidden>)
 >Re: Addressing Relationships in awakeFromInsert (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: NSNotifications between threads
  • Next by Date: NSImageView SubClass and Mouse Cursor problems
  • Previous by thread: Re: Addressing Relationships in awakeFromInsert
  • Next by thread: Re: Addressing Relationships in awakeFromInsert
  • Index(es):
    • Date
    • Thread