tags:

views:

646

answers:

3

I would like to add a field to an existing domain class. I do not want to lose my view files however as I know will happen if i run generate-all. Is there another way I can update the mapping etc?

A: 

just declare it:

class MyDomain {
    String newField;
}

Should be all you need to do.

Gareth Davis
That will overwrite the existing view which isn't what they want.
Jared
+1  A: 

There are a couple of ways to do this.

  1. If you have not modified your generated views too much and are using version control, you could allow grails to overwrite your views and then merge the changes to the new templates with what is in version control.

  2. If you have modified your generated views, you could just answer no to the prompt for overwriting the views. If you are only adding a new field, changing a field name or something simple like that, modifying the view templates should be pretty straight forward to do manually.

You would deal with any possible changes to the Controllers in the same way.

Lloyd Meinholz
+2  A: 

I think this is a common concern.

This is not a direct solution to your problem, but this is what I do and works very well for me.

  1. I never make direct modifications to the grails scaffolded artifacts (views and controllers)

  2. I keep my production views/controllers separate from the scaffolded artifacts; through I use the scaffolded as the starting point of my application controllers and views.

  3. If there are changes to the domain model, I re-generate the views and copy-paste (wherever possible) from scaffolded artifacts to hand-coded artifacts.

  4. At some point, I either delete all the scaffolded artifacts from the app or just protect access to them.

Hope this helps.

Deepak Mittal
How do you name your custom view/controllers? It seems you would have to diverge from the grails naming conventions to get this to work. This is a common issue and a nice solution would be great.
Lloyd Meinholz
Deepak Mittal