Re: Validation error in a relationship? (in coredata)
Re: Validation error in a relationship? (in coredata)
- Subject: Re: Validation error in a relationship? (in coredata)
- From: Chris Hanson <email@hidden>
- Date: Mon, 15 Oct 2007 14:37:37 -0700
On Oct 15, 2007, at 1:13 PM, dexter.cocoa dexter wrote:
Oh damn, I've tried to make a 1:n relationship to solve the previous
described problem. However I've a similar error with the 1:1 rel.
You can see it below, while this is my schema
(http://img100.imageshack.us/img100/5711/immagine1gr2.png) and this
the code for two used subclasses of nsmanagedobject if it can be
usefull... but it's a normal class (ANTStArticle:
http://paste.lisp.org/display/49214 - ANTStArticle_Content:
http://paste.lisp.org/display/49215)
Hell's Kitchen/Dexter/Malcolm:
I suspect the instances of both the DRAFT entity and the DRAFT_CONTENT
entity are in some sort of very invalid state. In your code pastes,
you appear to have substantially incorrect Core Data accessor methods.
For example, you have methods that look like this (paraphrased to
resolve some #define constants):
- (void)setMessageBody:(NSString *)body {
[self setPrimitiveValue:body forKey:@"body_text"];
}
- (NSString *)getBody {
return [self primitiveValueForKey:@"body_text"];
}
I doubt this is ever going to do what you want. (Plus it's
inconsistent with Cocoa naming conventions and with itself.) If
you're going to write accessors for your modeled properties, you need
to write them according to how the Core Data documentation specifies
your accessors need to be written; you also need to follow the
appropriate naming conventions for both the properties and the methods
so that all appropriate methods will be invoked at the appropriate
times.
In particular, subclasses of NSManagedObject *do not* enable automatic
notification of observers by default, unlike other subclasses of
NSObject. Thus you always need to include these in the
implementations of your accessor methods.
In this case, I would rename your attribute from "body_text" to
"messageBody" and write the accessor methods like this:
- (void)setMessageBody:(NSString *)value {
NSString *temp = [value copy];
[self willChangeValueForKey:@"messageBody"];
[self setPrimitiveValue:temp forKey:@"messageBody"];
[self didChangeValueForKey:@"messageBody"];
[temp release];
}
- (NSString *)messageBody {
NSString *value;
[self willAccessValueForKey:@"messageBody"];
value = [self primitiveValueForKey:@"messageBody"];
[self didAccessValueForKey:@"messageBody"];
return value;
}
The -{will,did}{Change,Access}ValueForKey: invocations are critical to
ensuring correctness within your application.
-- Chris
PS - It would be helpful to stick to one identity when asking
questions on cocoa-dev, as it can help "fill in" context between
questions. Which isn't to say each question shouldn't also stand on
its own. Both are important when participating in a technical
community.
_______________________________________________
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