Hi Kevin,

On Jun 3, 2011, at 12:53 PM, Kevin Hinkson wrote:
> On 3 Jun 2011, at 15:10, Chuck Hill wrote:
> 
>>> When one of my checks fail I do:
>>> 
>>> throw new NSValidation.ValidationException("Please enter a valid email 
>>> address.");
>>> 
>>> In either case (with only one enabled at a time) validateForSave and 
>>> validateEmail can be seen throwing an exception which I log but this is 
>>> only thrown after the EO is inserted into the database which is done by 
>>> saving the editing context.
>> 
>> The EO is in the database when you get this error?  That seems unlikely.  It 
>> should be thrown during ec.saveChanges() before getting written to the 
>> database.  Check the stack trace.
> 
> It is, but not for the reason I thought. In validateEmail I was doing a 
> lookup to ensure that the email was not already in the database.

A better way is to use a unique constraint on the column in the database.  The 
downside of that is that the database exception is harder to interpret and 
varies between databases.


> Right after the EO is saved to the db, I have another EO being created, given 
> a relationship to the first EO and saved again, so the validateEmail is being 
> triggered on the second save. So I now exclude the current EO by matching on 
> it's primary key as well.
> 
> Is there a better way to create new EOs that have relationships other than:
> EO1 -> save.
> EO2 -> init -> add relationship to EO1 -> save both.
> 
> Is there a way to init EO1 and EO2, add the relationship and just have WO 
> take care of the rest?

There is no need for the first save.  Trust in EOF:

> EO1 -> init
> EO2 -> init
> -> add relationship to EO1
> -> save both.


Chuck



-- 
Chuck Hill             Senior Consultant / VP Development

Come to WOWODC this July for unparalleled WO learning opportunities and real 
peer to peer problem solving!  Network, socialize, and enjoy a great 
cosmopolitan city.  See you there!  http://www.wocommunity.org/wowodc11/

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to