Reputation: 129
I have following entities with a many-to-many relationships.
i'm making a small playlist app where the entity named Entity is for the playlists and the songs entity is for the songs. at the moment i have a viewcontroller where you can add playlists to the Entity and a viewcontroller where you can add songs to the song entity. The problem is that all the videos are shown in every playlists. How can i hook this relationship up between these 2 entities?
Do i need to make a attribute in Songs which hold a playlist id? or how will the Entity know which song belong in which Entity object?
Upvotes: 0
Views: 815
Reputation: 539685
First of all, I would suggest to choose slightly different names for the entities and relationships, in particular the singular form (Song, Playlist) for the entity name, and the plural form of the destination (songs, playlists) for to-many relationships:
Now the objects are "hooked up" by setting the relationship between them. Assume that you have a song and a playlist:
Song *songA;
Playlist *playlistB;
Now you can either call
[songA addPlaylistsObject:playlistB]; // (1)
or
[playlistB addSongsObject:songA]; // (2)
to establish a relationship between these two objects.
It does not matter whether which one you call because "songs" and "playlists"
are inverse relationships. songA
is added to playlistB.songs
,
and playlistB
is added to songA.playlists
.
Upvotes: 2
Reputation: 2224
Check this This is picture of the answer! You will need to use a table to couple the to tables together.
Upvotes: 0