UA-17470720-3

Jump to content


Photo
- - - - -

Core Data, SQLite, SSQL and Server repository--

data-stores models core-data web-services

  • Please log in to reply
1 reply to this topic

#1 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 06 January 2014 - 03:30 PM

Ok, need some ideas, hopefully from individuals who had to deal with same scenario.

 

I have core entities with relationships. Utilizing sqlite, after running the app in simulator you will find entities populated, and  the "relations" being created in sqlite tables that "essentially link" the tables together via integers. Naturally the
Z_PK, Z_OPT, and Z_ENT integers create the links. The Z_PK appears to be created automatically. After data is input, the core data is synced to cloud server with mssql database. When user lites up app again the data syncs down from the cloud. Now the problem is with populating the "relationship tables" in core data. I have created code to sync up and down using WEB service, MVC 5 etc., but now have run into the snafu of populating the "relationship tables"........

 

The problem in essence is populating the relationship tables with data that links both tables using the Z_PK, Z_OPT, and Z_ENT fields. IE, could I use the primary key fields from mssql tables to populate the Z_PK field for example?

 

Per chance does anyone have any direction to point me it--

 

Thanks

 

 



#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 08 January 2014 - 06:50 AM

Hi Todd,

 

I'm not syncing data between Core Data and a web server database, but I am exporting Core Data entities to a file via Email/Dropbox and then importing those files back into Core Data on another device.

 

The first thing with Core Data is that is NOT a database.

 

If you are going anywhere near the actual SQLite and specifically any of the Z_ values you are, IMHO, doing it wrong.

 

I assume you've "Created NSManagedObject Subclasses…" for all your Core Data entities. Using these subclasses is how you create your relationships.

 

For example, I have a set list app I'm working on, there is a SetListEntity and it can have many child SongEntity. 

 

If I import a new setlist I create the SetListEntity:

 

 

    NSEntityDescription *setlistDescription = [NSEntityDescription entityForName:kdgSetlistEntity inManagedObjectContext:kdgManagedObjectContext];

    SetlistEntity *setListEntity = [[SetlistEntity alloc] initWithEntity:setlistDescription insertIntoManagedObjectContext:kdgManagedObjectContext];

 

and then add any importing songs to it using the methods in the SetlistEntity subclass, in this case the addSongsObject: method:

 

 

NSEntityDescription *songEntityDescription = [NSEntityDescription entityForName:kdgSongEntity inManagedObjectContext:kdgManagedObjectContext];

SongEntity *songEntity = [[SongEntity alloc] initWithEntity:songEntityDescription insertIntoManagedObjectContext:kdgManagedObjectContext];

[setlistEntity addSongsObject:songEntity];

 

I've just show the one song here, there's obviously a for() loop iterating over the incoming data.

 

 

Anyway, that's how I'm doing, and it works for me.

 

HTH


Cheers,

Dave

www.dgapps.ie





Also tagged with one or more of these keywords: data-stores, models, core-data, web-services

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users