ios - Obtaining values of an attribute through relationships using Core Data - Currently passing NULL -


i have core data model 3 entities: transaction, occasion, person , when i'm fetching in transaction entity, getting "null" value in database. let me explain.

transaction in case, entity has relationships person , occasion. person entity has name attribute , relationship transaction entity. transactions (person entity) < ------ >> whoby (transaction entity).

there relationship categories attribute (occasion entity) < ---------------- >> event (transaction entity).

i @ basic stages of app. have 1 table view controller , when press plus button, you're asked, in modal view, add name , occasion. both displayed in table view name being main text of cell , occasion being subtitle.

when add inserted values user directly person entity, representing name attribute, works , see in table view. same goes occasion (separately person).

however, when add data directly transaction entity , use fetchrequest bring that, every time press save pass value , return table view, i'm presented (null).

my addentryvc has in save button method:

nsmanagedobject *newentry = [nsentitydescription insertnewobjectforentityforname:@"transaction" inmanagedobjectcontext:context]; [newentry setvalue:self.nametextfield.text forkeypath:@"whoby.name"]; 

in table view, have:

// there nsmutablearray property called transactions hold transactions nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] initwithentityname:@"transaction"]; self.transactions = [[managedobjectcontext executefetchrequest:fetchrequest error:nil]mutablecopy];

// in cellforrowatindexpath nsmanagedobject *transaction = [self.transactions objectatindex:indexpath.row];

[cell.textlabel settext:[nsstring stringwithformat:@"%@", [transaction valueforkeypath:@"whoby.name"]]]; 

when run this, there no errors/warnings , when add entry, see (null) saved result. when run same code, modifying transaction person directly, including mutablearray, works.

so i'm there.. appreciate assistance. feel relationship of whoby.name not working. because it's relationship. can't imagine i'd have go set person.name attribute; should work transaction?

i have tried predicate below fetch request:

fetchrequest.predicate = [nspredicate predicatewithformat:@"whoby.name = %@", self.persontransaction.name];

.. persontransaction @property (nonatomic, strong) person *persontransaction property , has same result.

thanks in advance

when operate on relationship have manually create entities, e.g. have replace:

nsmanagedobject *newentry = [nsentitydescription insertnewobjectforentityforname:@"transaction" inmanagedobjectcontext:context]; [newentry setvalue:self.nametextfield.text forkeypath:@"whoby.name"]; 

with like:

nsmanagedobject *transaction = [nsentitydescription insertnewobjectforentityforname:@"transaction" inmanagedobjectcontext:context]; nsmanagedobject *person = [nsentitydescription insertnewobjectforentityforname:@"person" inmanagedobjectcontext:context]; person.name = self.nametextfield.text; transaction.whoby = person; 

btw make sure read: core data programming guide - relationships , fetched properties.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -