• 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 properties using Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unique properties using Core Data


  • Subject: Re: unique properties using Core Data
  • From: Charilaos Skiadas <email@hidden>
  • Date: Wed, 13 Jul 2005 13:05:25 -0500


On Jul 13, 2005, at 11:29 AM, C Thomas wrote:


Core Data uses so much of the database paradigm that I expected to see an option to choose to make a property unique... but failing that, I am trying to implement uniquing myself...


My entity's name property needs to be unique within the managed object context. So, I'd like to validate it before I insert it, and 'validateForInsert' seems like the logical way to do that.

My problem is that I can't even set the property until I've already inserted the NSManagedObject into the context using (id) initWithEntity:(NSEntityDescription*)entity insertIntoManagedObjectContext:(NSManagedObjectContext*)context. By then, it's too late - I've already inserted it.

Can somebody explain how to use validateForInsert?

I am not sure I see the problem. Will validateForInsert do what you want it to if you call it after the init call? The managed object context is sort of a scratch pad. You put your object in there, then check if it lines up properly with all the other stuff you've got piled up in there (validateForInsert) , and if it doesn't you can throw it away (remove it from the context). There is no requirement for the data in the managed object context to be valid at all times. The validations will only be called when one attempts to save the data to a store.
So to put it plainly, I would in fact expect the object to go in the context before I can decide if it is valid or not. It's like, you can't know what's in the box until you open it (or use some x-ray machine that would cost too much, or in this case if you check manually that your name property does not conflict with any other properties already in the store).


Maybe I've misunderstood what you are trying to do? If you want the validateForInsert to happen automatically, you could override the object's awakeFromInsert to call validateForInsert, but you'll still have to remove the object manually by catching the exception.
In case i'm about to be advised to use validateValueForKey instead, I can't do that since core data seems to call that method for each object upon exit - to make sure that all of the objects are in a valid state, I suppose.

Is there some sort of context-dependant method like validateValueForInsert or something like that? For a property that must be unique, the property can be valid for insert, but once it's inserted it's no longer a valid property to insert.




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40math.uchicago.edu


This email sent to email@hidden


Haris


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >unique properties using Core Data (From: C Thomas <email@hidden>)

  • Prev by Date: Relationship on parent not observed properly for subentity (was: Abstract entities and relationships)
  • Next by Date: Re: LSUIElement and LSBackgroundOnly
  • Previous by thread: unique properties using Core Data
  • Next by thread: [ANN] Cocoa programming job opening in Portland, OR
  • Index(es):
    • Date
    • Thread