Say I have the following classes:
class Fruit { ... }
class Apple extends Fruit { ... }
class Orange extends Fruit { ... }
Let's say a user wants to create a new Apple
. They pick a type from a dropdown, and I use a service to translate the type string into a concrete type:
def fruit = FruitService.createFruit(params.type)
fruit.properties = params
fruit.save()
This will successfully save a new Apple
instance.
Now let's say the user realized that they made a mistake and that they wanted to create an Orange
instead. In the edit view, I provide the ability for the user to change the type to an Orange
, but how do I update the existing Apple
instance so that it's now an Orange
? I cannot simply delete the Orange
and create a new Apple
instance because of other relationships. Is this even possible?