core data - coredata- relationship failing to behave properly -


this structure of coredata architecture. enter image description here

after adding entries 'artists', using them newly added 'album' entries working perfect.

enter image description here

but problem shown in img- 2 & 3, after assigning 'michael jackson' 'insomniac 2010' album & adding same artist 'baby ft ludacris' losing reference album 'insomniac'.

this code save context in albumdetailviewcontroller.h

- (void)entityrecordstableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath forentity:(id)entity {     artist *selectedartist = entity;      uitableviewcell * cell = [tableview cellforrowatindexpath:indexpath];     [cell setselected:no animated:yes];      if ([self.pickedartists containsobject:selectedartist]) {         [self.pickedartists removeobject:selectedartist];         [cell setaccessorytype:uitableviewcellaccessorynone];         editingalbum.artist = self.pickedartists;         [self savethecontext:editingalbum.managedobjectcontext]; //        nslog(@"%d",self.pickedartists.count);     }     else {         [self.pickedartists addobject:selectedartist];         [cell setaccessorytype:uitableviewcellaccessorycheckmark];         editingalbum.artist = self.pickedartists;         [self savethecontext:editingalbum.managedobjectcontext]; //        nslog(@"%d",self.pickedartists.count);     } } 

i think there must problem in managedobjectcontext saving. should this

self.managedobjectcontext = [(appdelegate *)[[uiapplication sharedapplication] delegate] managedobjectcontext]; [self savethecontext:self.managedobjectcontext]; 

instead of

[self savethecontext:editingalbum.managedobjectcontext]; 

i tried failing work per expectations.

you can find source code here

i have updated code. please check same. problem in relationship between artist & album. must many many.

your relationship between album & artist 1 many. hence, if select artist multiple album override value. please check database same.

code : click here


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -