• 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
Core Data : awakeFromInsert
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data : awakeFromInsert


  • Subject: Core Data : awakeFromInsert
  • From: WhiteContainer <email@hidden>
  • Date: Thu, 9 Mar 2006 20:46:54 +0100

Hi,

About a Core Data document-based application...
3 entities A_stock<-->>B_transaction<<-->C_invoice
I want to keep an history of the prices for the sold stock items. That happens in B (transactions=items sold).
What I want : If the user changes the price (persistent attribute) of an item in A, the transaction prices (transient and dependant from the A value via a calculation trough the relationship) must not change. One item can be sold at different prices during his life-time in the stock (discount, gifts etc).
So for each transaction in B, I have to "snapshot" the stock price attribute at the moment of the sale, that means at the moment of the creation of a B instance.


Ideas and tests (that did not work...because of me fore sure...):
1-shut off the notification in A_stock with
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)theKey
////// it did'nt work

2-copy the value and stock it in a persistent attribute as a value totally independant from A_stock
/////i don't know how to do exactly


3-awakeFromInsert
I think it is the best solution : it's perfect for time stamps and id's.
But here, there is a problem : the value in transaction depends on the relationship B>A and relationships are not set up at this moment...


In the Xcode example iClass, look at how the developer reached in Person.m, the fonction getId from the entity IDgenerator, which is not related at all with person in the model :

>>>>>>>>

@implementation Person
- (void)awakeFromInsert {
[self setPrimitiveValue: [[[[NSApplication sharedApplication] delegate] idGenerator] getNewID] forKey: @"personID"];
}
@end


@implementation iClassAppDelegate
- (IDGenerator *)idGenerator {
    return idGenerator;
}
@end

@implementation IDGenerator
// This is unmodeled, because otherwise we get caught in a validation loop before saving
// since accessing the property during validation would cause it to change


- (NSNumber *)getNewID {
Some Stuff
}
@end
>>>>>>>>>>>>>>>




My actual code in my test project :

>>>>>>>>>>>>>>>>>>>>>
@implementation Stock
-(NSNumber*)givePrice
{
return [NSNumber numberWithDouble:[[self valueForKey:@"stockPrice"] doubleValue]];
}
@end


@implementation Transaction
- (void)awakeFromInsert {
[super awakeFromInsert];
[self setValue: [//////which path???to reach://// givePrice] forKey: @"transactionFinalPrice"];
}
@end
>>>>>>>>>>>>>>>>>>>>


Many, many, many thx in advance if you can concretely help me...
Best Regards



_______________________________________________
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: Core Data : awakeFromInsert
      • From: "Marcus S. Zarra" <email@hidden>
  • Prev by Date: Re: Design Decision: Passing Information Between Two Applications
  • Next by Date: Re: Core Data : awakeFromInsert
  • Previous by thread: Re: Category class method problem
  • Next by thread: Re: Core Data : awakeFromInsert
  • Index(es):
    • Date
    • Thread