Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

krayziekray

macrumors 6502
Original poster
Sep 24, 2008
333
0
127.0.0.1
Hi,

In my iOS app I'm loading an sqlite file from the app bundle into core data. This works perfectly fine, however, I want to know how i can add a many-to-many relationship in an SQL statement so i can populate my Database with the correct relationships. Let me explain a bit further.

I have two Entity's in my Core Data model. House and Owner. These two classes have a many-to-many relationship, so a House can have many Owners and a Owner can have many Houses.

I have set up the data model with the appropriate relationships, however, I'm not sure how to create the link in an SQL Statement.

With a one to many relationship I would simply add the Z_PK of the House row to the Z_OWNER column which would mean the house belongs to this owner. But how can I add a group of owners? something along the lines of {x, y, z} in the Z_OWNER column which would state the the Z_PK x,y&z (from the Houses entity) are the owners of this house and vice versa?

I hope you can help me :)

Thanks in advance! :)

KrayzieKray
 
If i understand correctly you should have a separate ownership table, e.g. Owners, Houses and then Ownership tables and the Ownership table has House -> Owner links.
 
If i understand correctly you should have a separate ownership table, e.g. Owners, Houses and then Ownership tables and the Ownership table has House -> Owner links.

Yeh, that's how I would develop my database if i were using a normal DBMS, but I'm just confused as to why there are many to many relationships in the Model in Xcode. Does core data create the third table? How do I get it to create this third table?

Sorry, I'm new to Core Data :eek:
 
Yes, it creates an internal table. FYI, I've found it easier just to forgo CoreData and use sqllite directly.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.