Re: Addressing Relationships in awakeFromInsert
Re: Addressing Relationships in awakeFromInsert
- Subject: Re: Addressing Relationships in awakeFromInsert
- From: Jim Correia <email@hidden>
- Date: Wed, 10 Aug 2005 16:12:28 -0400
On Aug 10, 2005, at 4:01 PM, August Trometer wrote:
I've got 2 Entities set up in a master-detail configuration. They
have inverse Relationships.
I've subclassed the Detail Entity and overridden the
awakeFromInsert method to add some default values (date added,
etc.). However, when I try to address the owner or Master via
valueForKeyPath, I get a Null return.
Here's a snippet from the Detail Entity:
- (void) awakeFromInsert
{
[super awakeFromInsert];
[self setValue:[NSDate date] forKey:@"dateCreated"]; // works fine
[self setValue:[self valueForKeyPath:@"master.createdBy"]
forKey:@"createdBy"]; // sets the value to NULL
}
I'm sure I'm missing something here -- it does seem to be the best
place for this sort of default setting -- but I can't seem to
figure out how to address the Master object. I've also tried simply
NSLogging [self valueForKeyPath:@"master"] and it, too, returns Null.
awakeFromInsert is sent to your object just after it is created. When
do you set the value for master?
Did you write an accessor for setMaster and also sync the createdBy
value there?
(It is hard to tell from your limited example, but if self.createdBy
and master.createdBy are supposed to always be the same value, it may
make sense to remove the redundant information in one place so that
they never have the opportunity get get out of sync.)
Jim
_______________________________________________
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