Re: CoreData modeling a mutable attribute set for an entity
Re: CoreData modeling a mutable attribute set for an entity
- Subject: Re: CoreData modeling a mutable attribute set for an entity
- From: Jeff LaMarche <email@hidden>
- Date: Tue, 3 Jan 2006 12:59:20 -0500
Jesse:
I'm not sure, but it's possible that Core Data inheritance isn't the
right choice. I haven't used it, but I remember that under EOF, use
of inheritance was discouraged, though I don't know the reasoning
behind that.
Perhaps you should pick a single attribute type to use for your
concrete attribute, and then create transient attributes to translate
it into other values. Do you intend for @"2" to be different from 2.0
for some reason? Can't you just use strings for both key and value?
I'm not sure what exactly your needs are, but I'm guessing that
you're setting yourself for some significant headaches on this path :-/
Sorry I can't be more help.
Jeff
On Jan 3, 2006, at 12:48 PM, Jesse Grosjean wrote:
In a Fetch Requestion, you can, however, use any of an entity's
properties - including its relationships, not just its attributes
- so since you have a relationship from Entry to EntryAttribute,
you can create a single predicate using keypaths based on the
relationship name. So, using your example, you could create a
format string something like:
entryAttributes.value = 'foo'
or
entryAttributes.value = $VALUE
If I understand what you want, that should work to allow you to
fetch Entry entities based on the EntryAttributes it contains.
Yes that's what I'm trying to do. This predicate on the key works
(because all EntryAttributes have a key of type string):
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY
entryAttributes.key like 'name'"];
But if I try to query values:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY
entryAttributes.value like 'name'"];
it fails giving me this error "Can't do regex matching on object 1."
I think the reason is because the concrete subclass entities of my
EntryAttribute entity have different types for the value key. For
example EntryStringAttribute has a string typed value while
EntryBooleanAttribute has a boolean typed value. But the query
machinery doesn't know about this and fails when it runs into a
typed value that it doens't understand.
Here's the code that I'm using to set up my test.
NSManagedObject *entry = [NSEntityDescription
insertNewObjectForEntityForName:@"Entry"
inManagedObjectContext:managedObjectContext];
NSManagedObject *booleanAttribute = [NSEntityDescription
insertNewObjectForEntityForName:@"EntryBooleanAttribute"
inManagedObjectContext:managedObjectContext];
NSManagedObject *stringAttribute = [NSEntityDescription
insertNewObjectForEntityForName:@"EntryStringAttribute"
inManagedObjectContext:managedObjectContext];
[booleanAttribute setValue:@"status" forKey:@"key"];
[booleanAttribute setValue:[NSNumber numberWithBool:YES]
forKey:@"value"];
[stringAttribute setValue:@"name" forKey:@"key"];
[stringAttribute setValue:@"jesse" forKey:@"value"];
[[entry mutableSetValueForKey:@"entryAttributes"]
addObject:booleanAttribute];
[[entry mutableSetValueForKey:@"entryAttributes"]
addObject:stringAttribute];
I'm guessing that their isn't a strait forward way to query this.
But I'd still like to know if anyone has suggestions on where to go
next.
PS, in the model screenshot that I posted
http://www.hogbaysoftware.com/files/deletememutableattributeset.png
The entryAttributes relationship should really be a to many
relationship. That's what I'm using for my tests.
Thanks,
Jesse
_______________________________________________
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