core data - setPropertiesToFetch: and setReturnsObjectsAsFaults:NO with relationships -


the problem using setpropertiestofetch: , setreturnsobjectsasfaults:no setting relationship cause 2 additional "select ..." on sqlite3 database.

i have task , job model relationship between them. task has 1 job , job_id , job has 1 task. im importing lot of tasks , jobs. speed process import tasks , jobs first before setting relationship. import works fine. when set relationship unexpectedly happen. use following code set relationships.

int limit = 100; nsmanagedobjectcontext *moc = [appdelegate newmoc]; nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init]; [fetchrequest setentity:[nsentitydescription entityforname:@"task" inmanagedobjectcontext:moc]]; [fetchrequest setpredicate:[nspredicate predicatewithformat:@"job = nil"]]; [fetchrequest setreturnsobjectsasfaults:no]; [fetchrequest setreturnsdistinctresults:yes]; [fetchrequest setfetchlimit:limit]; [fetchrequest setpropertiestofetch:[nsarray arraywithobjects:@"job", @"job_id", nil]]; [fetchrequest setshouldrefreshrefetchedobjects:no]; [fetchrequest setincludessubentities:no];  while (true) {     @autoreleasepool {         nserror *error = nil;         nsarray *tasks = [moc executefetchrequest:fetchrequest error:&error];                    if (!error) {             if (tasks.count > 0) {                  nsmutableset *jobids = [[nsmutableset alloc] init];                                  (task *task in tasks) {                                          [jobids addobject:task.job_id];                 }                                     nsarray *jobs = [listobjectsmanager objectsforids:jobids properties:[nsarray arraywithobjects:@"baseobjectid", @"task", nil] entityname:jobclassname moc:moc];                 [jobids release];                 (task *task in tasks) {                      (job *job in jobs) {                          if (task.job_id.intvalue == job.baseobjectid.intvalue) {                             task.job = job;                             job.task = task;                             break;                         }                     }                 }                 [appdelegate savecontext:moc];             }             else {                 //no more relationships set                 break;             }         }         else {             nslog(@"error fetching : %@", error.localizeddescription);         }     } }  [fetchrequest release]; 

the line task.job = job creates 2 new "select ..."!?!

this produce lot of selects i'd avoid.


addition

nsarray *tasks = [moc executefetchrequest:fetchrequest error:&error]; 

creates "select t0.z_ent, t0.z_pk, t0.zjob, t0.zjob_id ztask t0 t0.zjob null limit 100" works expected.

nslog(@"%d", [tasks objectatindex:0].job_id.intvalue); 

creates no new "select..." works expected.

[tasks objectatindex:0].job_id = [nsnumber numberwithint:63]; 

creates:

2013-05-10 00:26:59.048[1197:1803] coredata: sql: select 0, t0.z_pk, t0.z_opt, t0.zbaseobjectid, t0.zbaseobjectname, t0.zjob_description, t0.zjob_id, t0.zjob ztask t0 t0.z_pk = ? 2013-05-10 00:26:59.058[1197:1803] coredata: annotation: sql connection fetch time: 0.0099s 2013-05-10 00:26:59.061[1197:1803] coredata: annotation: total fetch execution time: 0.0133s 1 rows. 2013-05-10 00:26:59.064[1197:1803] coredata: annotation: fault fulfilled database : 0x1f540670

why fault fulfilled when property set , how can avoid that?

thanks in advanced!


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -