Re: validateXXX not called on a relationship set to null
Re: validateXXX not called on a relationship set to null
- Subject: Re: validateXXX not called on a relationship set to null
- From: John Pollard <email@hidden>
- Date: Tue, 04 Mar 2014 12:08:41 +0000
Please see below...
On 27 Feb 2014, at 17:01, Ramsey Gurley <email@hidden> wrote:
>
> On Feb 27, 2014, at 6:43 AM, John Pollard <email@hidden> wrote:
>
>> Hi List,
>>
>> I am trying to pin down where a to-one relationship is getting set to null inappropriately.
>
>
> Override takeStoredValueForKey on the EO and look for the null value for that key. That will pinpoint the moment it is being set to null.
Ok thanks. For a new object where the relationship is null (not set), the validateXXX does get called to check the null (good) and no call is made to setXXX or takeStoredValueForKey (makes sense).
>
>
>> I added validateMyRelationship() to trap and throw and this is triggered ok when the base object is created / updated.
>>
>> However, it wasn't called when the relationship was set to null and hence the update proceeded, bypassing my trap.
>
>
> It did or did not get called when updating? These two sentences seem contradictory.
The first sentence applies to when the relationship is set to something, when it does get called.
The second sentence applies to the problem scenario I have, where the relationship is being nullified having previously been set to something, but with no call to validateXXX prior to the sql hitting the database setting the relationship to null.
Perhaps Chuck has sniffed it out with the Nullify relationship rule, will reply to his post separately.
>
> validateXXX will be called when you call ec.saveChanges() which calls validateForSave() which calls your validateXXX methods if they exist. Is it possible you override validateForSave or validateForUpdate and forget to call super? That would probably disable your validateXXX methods.
I do have validateForSave() which is calling super. But in my problem scenario, the relationship is changing to null without any validateXXX.
I don't yet know whether setXXX is called in my problem scenario (as I don't know how to replicate the problem scenario). I will add logging so
>
> The other way validateXXX is called is when validateTakeValueForKey is called. That is called automatically by component bindings. So if you bind a WOComponent directly to your EO’s attribute/relationship, it gets called there.
Ok, thanks
John
>
> If you just call setMyRelationship(), it is not called unless you’ve added validateTakeValueForKey to your eogen or something.
>
>
>> Does the above scenario ring any bells; why isn't validateMyRelationship() called when I can see the update request to the database follows.
>>
>> I can't set the relationship to mandatory as in some circumstances null is valid, though it should never change to null after it has been set.
>>
>> Thanks
>> John
>
>
> You have to be careful if this is not enforced in the database. You may validate it perfectly, but if the database allows it, you can end up in cases where your data is hosed by the Objective-C/PHP/Rails team down the hall. Then your validation methods start barfing out errors and everyone blames YOUR apps. “But it works fine on blahblah app! Why is your java crap crashing? What are you? Incompetent?”
>
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden