iphone - I want a core data entity which could relationally point to itself with many-to-many relationships. Category entity -
i want build category entity in core data. entityname=category. has 2 relationships called categoryparents , categorychildren relationships both configured "to-many" , reverse of each other. both destined entity "category" itself. want create recursive category entity child category may have more 1 parent category.
i want root categories not have parent categories.
but, 'to-many key not allowed here' error
here trying
-(nsarray *) getcategoriesroot { // construct fetch request nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init]; nsentitydescription *entity = [nsentitydescription entityforname:@"category" inmanagedobjectcontext:context]; [fetchrequest setentity:entity]; //nspredicate *predicate = [nspredicate predicatewithformat:@"(categoryactive == %@) , (categoryparents == nil)", [nsnumber numberwithbool:yes]]; //nspredicate *predicate = [nspredicate predicatewithformat:@"categoryparents.count = nil"]; nspredicate *predicate = [nspredicate predicatewithformat:@"categoryparents = nil"]; //nspredicate *predicate = [nspredicate predicatewithformat:@"(categoryactive == %@)", [nsnumber numberwithbool:yes]]; [fetchrequest setpredicate:predicate]; nserror *error = nil; nsarray *fetchedobjects = [context executefetchrequest:fetchrequest error:&error]; if ([fetchedobjects count]!=0) { return fetchedobjects; } else { return nil; } }
here get
2013-07-15 17:29:12.238 basf katalog[10206:c07] * terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'to-many key not allowed here' * first throw call stack: (0x1faa012 0x13e7e7e 0x10f2bd9 0x10f25f2 0x10f23c0 0x10f2195 0x10f1977 0x10f1464 0x10f05dd 0x10ee539 0x3999 0x37e3 0x22f4 0x19157 0x19747 0x1a94b 0x2bcb5 0x2cbeb 0x1e698 0x1f05df9 0x1f05ad0 0x1f1fbf5 0x1f1f962 0x1f50bb6 0x1f4ff44 0x1f4fe1b 0x1a17a 0x1bffc 0x207d 0x1fa5) libc++abi.dylib: terminate called throwing exception
here core-data
it first time post stack overflow can not upload screenshot of entity, yet! want entity has relationships inverse of each other , pointing entity itself. both to-many categoryparents <<------>> categorychildren 1 category may have many parent categories 1 category may have many child categories
i new core data. pls help!
[nspredicate predicatewithformat:@"categoryparents.@count = 0"];
should work.
Comments
Post a Comment