Mailing List webobjects-dev@wocommunity.org Message #245
From: Faizel Dakri <webobjects-dev@wocommunity.org>
Subject: Re: [WO-DEV] Re: ERXGenericRecord takeValueForKey
Date: Mon, 30 Aug 2021 09:35:29 -0500
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
Oops, sorry, I see that you’re already overriding canAccessFieldsDirectly() to return false.

F

--
Faizel Dakri


> On Aug 30, 2021, at 9:29 AM, Faizel Dakri <webobjects-dev@wocommunity.org> wrote:
>
> If your EOs are inheriting from EOGenericRecord, they most likely are implementing EOKeyValueCoding, which is an extension to NSKeyValueCoding that uses a couple of special methods to set/retrieve model properties:
>
>    - takeStoredValueForKey()
>    - storedValueForKey()
>
> If you want your EO to behave using standard NSKeyValueCoding rules, try overriding canAccessFieldsDirectly() in your EO class (static method) to return false.
>
> F
>
> --
> Faizel Dakri
>
>
>> On Aug 25, 2021, at 8:50 PM, webobjects-dev@wocommunity.org wrote:
>>
>> Hi there,
>>
>> I must be missing something darn obvious; looks like I've missed EOF 101 somehow :/
>>
>> My EO class, which extends ERXGenericRecord, does not implement modelled property setters. Thus, I assumed takeValueForKey would always fall through handleTakeValueForUnboundKey. Seems not.
>>
>> I've overridden the methods like this:
>>
>> ===
>> class OCSEnterpriseObject extends ERXGenericRecord {
>> static boolean canAccessFieldsDirectly { NO }
>> void takeValueForKey(value,String key) {
>>   println "???takeValueForKey $key"
>>   //super.takeValueForKey(value, key) // precisely same behaviour as with the thing below, no difference
>>   NSKeyValueCoding.DefaultImplementation.takeValueForKey(this,value,key)
>> }
>> void handleTakeValueForUnboundKey(value,String key) {
>>   println "???handleTakeValueForUnboundKey $key"
>>   // ... some stuff to simulate setter (eventually using takeStoredValueForKey), not relevant, for it is never called
>> }
>> ...
>> }
>> ===
>>
>> It does NOT work as (I've naïvely) presumed.
>>
>> When eo.takeValueForKey(o,key) is called, I can always see “???takeValueForKey” (naturally), but I *never ever* see “???handleTakeValueForUnboundKey“ for any key amongst modelled attributes. Nothing other (known to me) gets called — not even takeStoredValueForKey, which I've also overridden to log —, but the value is set all right in the EO.
>>
>> Only if foo is a random (non-existing, non-modelled) string, I can see “???handleTakeValueForUnboundKey“.
>>
>> Looks like there's some trick in NSKeyValueCoding.DefaultImplementation.takeValueForKey which recognises modelled attributes in EOGenericRecord and fill their values directly, without falling to handleTakeValueForUnboundKey?!? Weird.
>>
>> Or I must be doing something very far wrong.
>>
>> Is this documented somewhere? Far as I can say, neither ERXGenericRecord nor EOGenericRecord nor NSKeyValueCoding.DefaultImplementation mentions anything special; NSKeyValueCoding.DefaultImplementation.takeValueForKey should simply check for the accessor (either with or without the _ prefix) and if there is none (which there indeed is not), fall to handleTakeValueForUnboundKey. What am I missing here?
>>
>> Thanks,
>> OC
>>
>>
>>
>> #############################################################
>> This message is sent to you because you are subscribed to
>> the mailing list <webobjects-dev@wocommunity.org>.
>> To unsubscribe, E-mail to: <webobjects-dev-off@wocommunity.org>
>> To switch to the DIGEST mode, E-mail to <webobjects-dev-digest@wocommunity.org>
>> To switch to the INDEX mode, E-mail to <webobjects-dev-index@wocommunity.org>
>> Send administrative queries to  <webobjects-dev-request@wocommunity.org>
>>
>>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <webobjects-dev@wocommunity.org>.
> To unsubscribe, E-mail to: <webobjects-dev-off@wocommunity.org>
> To switch to the DIGEST mode, E-mail to <webobjects-dev-digest@wocommunity.org>
> To switch to the INDEX mode, E-mail to <webobjects-dev-index@wocommunity.org>
> Send administrative queries to  <webobjects-dev-request@wocommunity.org>
>

Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster