Mailing List webobjects-dev@wocommunity.org Message #247
From: Morris, Mark <webobjects-dev@wocommunity.org>
Subject: Re: [EXTERNAL] [WO-DEV] Re: ERXGenericRecord takeValueForKey
Date: Wed, 1 Sep 2021 21:59:35 +0000
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
Hi,

Basically what Samuel said. Note that ERX- and EOGenericRecord work fine even if there is no subclass at all, just the model. This is in general a feature (e.g. there's no need for a special java class for a correlation table).

Regards,
Mark

On 9/1/21, 4:48 PM, "WebObjects & WOnder Development on behalf of Samuel Pelletier" <webobjects-dev@wocommunity.org> wrote:

    External email: Do not click the links. Verify legitimacy before taking action.

    Hi OC,

    I think the problem come from the fact ERXGenericRecord extends EOGenericRecord and this class behave like a map and do not need getter and setter for modelled attribute names. Getters and Setters created by EOGenerator are not required by EOF but they are very useful to add type checking to the code.

    By exploring tha NSKeyValueCoding with a decompiler, we can see that this method is called to get the method to set a value for a key: _storedKeyGetBindingForKey(String key) declared in the _KeyBindingCreation interface. My guess is the EOGenericRecord implementation of this method do some magic to enable EOGenericRecord map like behaviour for modelled attributes.

    So, if you want to disable attribute setters, you may either
    - rename the attribute and create a getter that call the real attribute getter
    - implement a setter that throw an exception
    - add some checking in takeValueForKey and also takeStoredValueForKey (to block both ways)

    Maybe extending EOCustomObject directly would also works but you will loose all the ERXGenericRecords stuff...

    Regards,

    Samuel


    > Le 25 août 2021 à 21:50, ocs@ocs.cz <webobjects-dev@wocommunity.org> a écrit :
    >
    > 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