RE: Unique items in Core Data models
RE: Unique items in Core Data models
- Subject: RE: Unique items in Core Data models
- From: "David Hazel" <email@hidden>
- Date: Tue, 15 May 2007 22:24:29 +0100
- Importance: Normal
I missed the start of this thread, so I may be saying something that's
already been touched on.
The publishing world uses ISBNs to uniquely identify books. Those can be
relied upon to be unique, so could potentially be used as a unique ID in any
data model. Whether they are practical is another matter, and depends on the
situation you're trying to model. They are only useful if (a) the books have
them (i.e. are published books rather than, say, PhD theses), and (b) the
user can be assumed to know them.
Apologies if none of the above is relevant to the discussion. Like I said, I
missed the start of this.
David Hazel
-----Original Message-----
From: cocoa-dev-bounces+david.hazel=email@hidden
[mailto:cocoa-dev-bounces+david.hazel=email@hidden]On
Behalf Of Chris Hanson
Sent: 15 May 2007 22:07
To: Keith Penrod
Cc: email@hidden
Subject: Re: Unique items in Core Data models
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
_______________________________________________
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