views:

38

answers:

1

I have very simple circular (or self-reflecting) relationship core data model in my iPhone word game. Entity Word has one-to-many relationship to/with itself which points to related words:

alt text

I use NSPersistentDocument Core Data Mac OS X template application to import words to Core Data sqlite database.

After importing data I can see all relationships being imported correctly (every word has at least one or more related words to it).

However, after saving database to sqlite file and reopening it again there is huge loss of related words pointers (words are still there but relationships are gone - NSLog shows null for them). It could be sometimes up to 50% loss of related words information.

When I store my database as XML or binary file and reopen it, all relationships are being save properly.

Can anyone point me why saving to sqlite file can cause loss of some relationships data when XML and binary versions of the same database stores everything correctly?

I am interested in sqlite because it has opinion of being more (memory) efficient when using in iPhone and of course produces significantly smaller database file size.

+1  A: 

That is not a one-to-many relationship. That is a -to-many relationship. It has no inverse. You can tell this because there are only arrows on one end of the line. Try adding the inverse relationship and see if that helps.

Dave DeLong
Thanks for being specific. I prefer to keep this relationship as a loose one. Anyway: what would be the reason other formats (XML and binary) save this relationship properly?
Lukasz