Ask Your Question
1

Is it possible to personalize the names of columns in an abstract domain class using Grails?

asked 2023-05-30 00:09:16 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-30 00:22:02 +0000

pufferfish gravatar image

Yes, it is possible to personalize the names of columns in an abstract domain class using Grails. This can be done by using the static mapping block in the domain class and specifying a column attribute for each property that needs to be customized.

For example, suppose we have an abstract domain class Person:

abstract class Person {
    String firstName
    String lastName
}

If we want to customize the column names for firstName and lastName, we can do it like this:

abstract class Person {
    String firstName
    String lastName

    static mapping = {
        firstName column: 'first_name'
        lastName column: 'last_name'
    }
}

This will create columns named first_name and last_name in the database table for each subclass of Person.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-30 00:09:16 +0000

Seen: 7 times

Last updated: May 30 '23