• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unique items in Core Data models
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unique items in Core Data models


  • Subject: Re: Unique items in Core Data models
  • From: Chris Hanson <email@hidden>
  • Date: Tue, 15 May 2007 14:07:28 -0700

On May 14, 2007, at 6:38 PM, Keith Penrod wrote:

Is there a way to set it up so that one of the attributes for an Entity is a sort of identifier--that is, every Book has a title and only one book can exist for any given title--kind of like a NSDictionary? So, if the user tries to create a new item and name it the same title it will either ignore the request, combine the info for the two books, or raise an error message.

Core Data doesn't do this; it's up to you to do this by normalizing your data model. What Core Data does do is ensure that every instance of an entity has a unique ID.


For example, a normalized data model for the above would involve a Book entity with a to-one title *relationship* to a Title entity, which has a to-one inverse relationship to a Book entity:

    Book.title <---> Title.book

Programmatically you would make sure that Titles are unique, and the use of a bidirectional to-one relationship ensures Book uniqueness.

Ultimately this is a data modeling problem. Trying to create your own "unique identifiers" typically means you're trying to solve it at the wrong layer, unless you're doing so for very specific reasons (e.g. you're interfacing with another system and need to map between your managed objects and objects in the other system).

  -- Chris

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Unique items in Core Data models
      • From: mmalc crawford <email@hidden>
    • RE: Unique items in Core Data models
      • From: "David Hazel" <email@hidden>
References: 
 >Unique items in Core Data models (From: Keith Penrod <email@hidden>)

  • Prev by Date: Re: entity referencing self in relationship
  • Next by Date: RE: Unique items in Core Data models
  • Previous by thread: Re: Unique items in Core Data models
  • Next by thread: RE: Unique items in Core Data models
  • Index(es):
    • Date
    • Thread