Mailing List webobjects-dev@wocommunity.org Message #140
From: Aaron Rosenzweig <webobjects-dev@wocommunity.org>
Subject: Re: [WO-DEV] ERXCopyable.CopyType = Nullify on to-many relationship should empty instead
Date: Fri, 9 Apr 2021 20:19:36 -0400
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
Hi Ricardo, 

My pleasure, here’s the pull request: https://github.com/wocommunity/wonder/pull/945

Speaking of toMany relationships…

Why did the database administrator leave his wife? 
She had one-to-many relationships.

On Apr 9, 2021, at 6:32 PM, Ricardo Parada <webobjects-dev@wocommunity.org> wrote:

Hi Aaron,

Got it. Thanks for the heads up. 

Do you have any plans to submit a pull request for your fix? 

Ricardo Parada 


Sent from my iPhone

On Apr 1, 2021, at 10:02 AM, Aaron Rosenzweig <webobjects-dev@wocommunity.org> wrote:

Ricardo (and friends) - heads up. 

We modified our local branch of WOnder to not null out the toMany relationship. 

We made an innocent mistake of setting an empty immutable NSArray. 

Even though most API methods return an interface of “NSArray” internally the data structure is mutable. I believe the primary idea is that people shouldn’t add/remove from the array directly. That said, internally, you do need a mutable data structure. 

It must be an empty mutable NSMutableArray that you set. If you don’t, when you try to add something to the toMany relationship it will fail. 


On Mar 25, 2021, at 2:11 PM, Ricardo Parada <webobjects-dev@wocommunity.org> wrote:

I’m gonna play with it but I see a couple of things to advance this.

One is to have an ignoresToManyNullify property that defaults to false so that we don’t change the existing behavior. 

Then for us who don’t want to deal with null to-many relationships. We could set the property to true. 

Another option is to allow Skip to work on relationships. 

Thanks Aaron for the feedback. 

I think that code was written by David Avendasora. 

Ricardo


On Mar 25, 2021, at 1:35 PM, Aaron Rosenzweig <webobjects-dev@wocommunity.org> wrote:

Hi Ricardo,

I have similar feelings as you do that it’s not right as is. 

I believe the original author had in their mind “a perfect copy” - meaning that if there was something the copy got from awakeFromInsertion “for free” then it isn’t really a copy of the source… so the author asked us to nullify. 

That said, there are issues with the current state of affairs:

1) “Nullify” for a toMany relationship should not set it to “null” - it should at least set it to an empty array. Having it “null” can cause us gas because we are not expecting toMany relationships to ever be null… they can be empty arrays but not null. 

2) “Skip” is valid for attributes, why not have it valid for relationships? If we “skip” then we can leave it alone. For some reason, the author expressly didn’t want relationships to be skipped. It’s presently a syntax error. 

Cheers,
— Aaron

On Mar 25, 2021, at 1:25 PM, Ricardo Parada <webobjects-dev@wocommunity.org> wrote:

I think ERXCopyable.java: 1286 should be changed to something like this:

case NULLIFY:
    // Only set to-one relationships to null. For to-many relationships we leave it alone with the empty array setup during the creation of the EO
    if (!relationship.isToMany()) {
        destination.takeStoredValueForKey(null, relationshipName);
    }




On Mar 25, 2021, at 1:02 PM, Ricardo Parada <webobjects-dev@wocommunity.org> wrote:

Hello everyone,

I like that in Wonder when you create an EO all the to-many relationships are initialized to an empty array because it means that I don’t have to worry about null checking every time I access the to-many relationship in order to avoid NullPointerExceptions. 

However, if I create my EO by copying an existing one using ERXCopyable then any to-many relationships that have ERXCopyable.CopyType set to Nullify will be set to null. 

Wouldn’t it be better to set them to an empty array? Or should we have an Emptify option?

Thanks
Ricardo Parada



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