Thanks all!

I had no big luck with overridden accessors: for one, it was sort of at the 
dangerous side, never sure whether I won't forget one or two. And besides, I 
can be wrong, but it seems to me sometimes EOF does not go through the 
accessors, but changes the underlying data directly — e.g., if an object in a 
relationship gets deleted, my removeObjectFromFoo was never called (perhaps I 
did something wrong at my side).

Eventually, I have tried the code below in my EO constructor (although the 
observe thing is my own undocumented String extension, I believe it's behaviour 
would be self-evident), and so far it seems to work quite nicely. Will see when 
testers get the thing to their hands :)

===
    EOEditingContext.ObjectsChangedInEditingContextNotification.observe { 
NSNotification nn ->
        if (!editingContext) return // seems we might get the notification a 
bit too soon in the object's lifetime; awakeFromInsertion/Fetch might be better 
choice
        
[EOObjectStore.UpdatedKey,EOObjectStore.DeletedKey,EOObjectStore.InsertedKey,EOObjectStore.InvalidatedKey].each
 {
            nn.userInfo[it].each { eo ->
                if (eo===this) {
                    Map chg=this.changesFromCommittedSnapshot()
                    ... process changes as needed ...
                }
            }
        }
    }
===

Thanks and all the best,
OC

> On 25. 5. 2020, at 6:39 AM, Michael Sharp <getsh...@gmail.com> wrote:
> 
> ERXGenericRecord.changesFromCommittedSnapshot
> 
> if (changesFromCommittedSnapshot().containsKey(MY_KEY)) {
>  propertyDidChange(MY_KEY);
> }
> 
> As mentioned by Aaron this could be wedged into overridden setters, 
> validate<Attribute> methods or even worked into your eogen template if you 
> wanted this behaviour model wide.
> 
> It might also be worth looking at the audit trail implementation in 
> ERCoreBusinessLogic for ideas on a configurable observer/notifier.
> 
> Sharpy.
> 
> 
> 
>> On 25 May 2020, at 10:40 am, ocs--- via Webobjects-dev 
>> <webobjects-dev@lists.apple.com> wrote:
>> 
>> Hi there,
>> 
>> I'd need to get a notification whenever a property of my EO changes, be it 
>> directly through a setter, or through an inverse-relationship being 
>> maintained, or through an object of an M:N deleted, whatever way. Something 
>> like
>> 
>> class MyEO extends ERXGenericRecord {
>> void propertyDidChange(String key) {
>>   ... to be called just after any property of mine changes, with its key ...
>> }
>> }
>> 
>> Does EOF or WOnder provide something like that? Whatever I try, I can't find 
>> it. I could easily observe willChanges of course, but that's something 
>> rather different...
>> 
>> Thanks,
>> OC
>> 
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/getsharp%40gmail.com
>> 
>> This email sent to getsh...@gmail.com
> 

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

This email sent to arch...@mail-archive.com

Reply via email to