On Feb 27, 2014, at 6:43 AM, John Pollard <[email protected]> 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. > 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. 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. 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. 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 protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
