• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting from one subclass to another
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting from one subclass to another


  • Subject: Re: Converting from one subclass to another
  • From: Chuck Hill <email@hidden>
  • Date: Wed, 13 Feb 2008 12:43:26 -0800


On Feb 13, 2008, at 12:26 PM, David Avendasora wrote:

Well, I've got it working, somewhat. I'm creating a new instance of the other subclass, copy all the attributes and relationships over, then delete the old instance.

The problem I'm having is that I'm somehow getting two instances of the target subclass. Maybe someone can look at this code and tell me what I'm doing wrong.

public void setNutritionValueType(NutritionValueType aValue) {
	if (nutritionValueType() == null || aValue == null) {
		super.setNutritionValueType(aValue);
	} else if (aValue != nutritionValueType()) {
		CalculatedNutritionValue nv = new CalculatedNutritionValue();
		editingContext().insertObject(nv);
editingContext().deleteObject(nutritionValueType());
nv.setIsSuspect(isSuspect());
nv.addObjectToBothSidesOfRelationshipWithKey(nutritionBlock(), "nutritionBlock");
nv.addObjectToBothSidesOfRelationshipWithKey(nutritionElement(), "nutritionElement");
nv.addObjectToBothSidesOfRelationshipWithKey(aValue, "nutritionValueType");
nv.setSortOrder(sortOrder());
nv.addObjectToBothSidesOfRelationshipWithKey(unitOfMeasure(), "unitOfMeasure");
nv.setValueQuantity(valueQuantity());
editingContext().deleteObject(this);
That seems wrong.
	}
}

It seems very simple. I just don't get where I'm getting a second instance. If I save the EditingContext, I do get two new records in the DB.

Any guesses? Anyone?

My first guesses.

Chuck



On Feb 13, 2008, at 3:01 PM, Ken Anderson wrote:

David,

I've been down this path many times, and my current recommendation is to just have some kind of type on the object that identifies it as one or the other. I have a situation where I store the class name of a 'calculator' class in the EO, and then dynamically call static methods on that class to do the heavy lifting.

Ken

On Feb 13, 2008, at 11:15 AM, Mike Schrag wrote:

I could just create a new object of the new class and delete the existing one
yes

What is the best way to get WO to pickup the subclass change immediately?

Or is this just a bad way of doing things?
yes

Inheritance hierarchy is to be treated like a PK -- It's an unchanging attribute of an EO. In fact, it's actually part of the EOGlobalID.

What you're describing is very similar to the Employee vs Manager modeling problem. The general consensus is that when an Employee becomes a Manager, it's not changing types, it's changing Roles, so it's actually a Person=>Role, where Role is Manager or Employee and you are just changing the relationship, not the intrinsic type.

You should consider type to be immutable for your own safety and the safety of those around you. The correct way is to delete your old class and make a new one, or maintain a relationship to (something like) a NutrionValueCalculator that changes (if there is a lot of other state in this object other than just this value).

ms

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40anderhome.com


This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40avendasora.com


This email sent to email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40global-village.net


This email sent to email@hidden

--

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects






_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Converting from one subclass to another (From: David Avendasora <email@hidden>)
 >Re: Converting from one subclass to another (From: Mike Schrag <email@hidden>)
 >Re: Converting from one subclass to another (From: Ken Anderson <email@hidden>)
 >Re: Converting from one subclass to another (From: David Avendasora <email@hidden>)

  • Prev by Date: Re: [ANN] JBND update
  • Next by Date: Re: Converting from one subclass to another
  • Previous by thread: Re: Converting from one subclass to another
  • Next by thread: Re: Converting from one subclass to another
  • Index(es):
    • Date
    • Thread