2

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?

Daniel T.
  • 37,212
  • 36
  • 139
  • 206
  • can you elaborate more on the "other relationships" part? If you update apple to become an orange, won't you want to change the relationships associated with the original apple object too? – Arturo Dec 11 '12 at 13:45
  • http://stackoverflow.com/questions/5725362/how-to-change-a-domain-class-model-object-from-one-derived-class-to-another-in-g –  Dec 11 '12 at 16:23

0 Answers0