Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3722722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:00:31+00:00 2026-05-19T06:00:31+00:00

I’m looking for some help with CoreData and with Entities in general. For the

  • 0

I’m looking for some help with CoreData and with Entities in general. For the purpose of my question, lets say I have a database of albums. I simple have an entity named albums with Attributes for Name, Artist, Year, Album Art, and such.

Now, lets say I want to be able to create songs for this album. I’m thinking I should have a separate Entity for the songs, and have a one-to-many relationship with it. However, I’m not sure exactly how I would do that.

Since I have different albums which contain different songs, I want to separate the songs from AlbumA from Album B. Now, I could have a row in the songs database for which album it belongs to, but is that the most efficient way to do this. What if I have a duplicate album name. I tried creating a unique “hash” of the album name using the time created and the name, but is there a better way.

I also need a better way to handle deletion for when an album is deleted.

Without using one-to-many relationships, I was able to create two separate entities, Albums and Songs, which aren’t linked together. However, when I create a new album, it loads a new viewcontroller and passes the “hashes” time-stamped album name to the viewcontroller. Then when I create a new song, it uses that hashed time-stamped album name as a row in the Songs entity. That way, when I’m viewing which songs are in the album, I just set an NSPredicate to only show queries which include the hashes time-stamp. However, deletion is a problem because their are no relationships.

  1. Should I be using a “one-to-many relationship”?
  2. How should I handle determining whether an song belongs to a certain album?
  3. What if their are multiple albums with the same name?
  4. How do I handle deletion?

If anyone could provide answers, code, or tutorial for any of these… it would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T06:00:33+00:00Added an answer on May 19, 2026 at 6:00 am

    So, hopefully this brief answer will get you on track:

    A one-to-many relationship is appropriate for album->songs. As to how to create it – let’s assume you have two entities, one called “album” and one called “song”. In XCode’s data model window, select your ‘album’ entity and create a new relationship (hit the + button in the properties table).

    Give your relationship a name, decide whether it’s optional or not (one would assume not, since every album must have at least one song in it), and select “song” as your destination entity. Finally, click the checkbox marked “To-Many relationship”. And that’s it!

    Now that you’ve established a relationship, any songs that are associated with an album will be deleted when you delete the album itself.

    Regarding question 3: “what if there are multiple albums with the same name”. This is fairly common scenario. It would be very unusual to use an english string as your primary identifier. You want to have some kind of unique ID for each album – this would be your primary/unique key. If you’re confused about what that means you should look into some more basic database concepts to get a better handle on it before moving on with Core Data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.