(Quick Reference)
create-domain-class
Purpose
The
create-domain-class
command creates a domain and associated integration test for the given base name.
Examples
grails create-domain-class
grails create-domain-class Book
grails create-domain-class org.bookstore.Book
Description
Creates a domain class for the given base name. For example, for a base name "org.bookstore.Book" a domain class called
Book
will be created in the
grails-app/domain/org/bookstore
directory. The argument is optional, but if you don't include it the command will ask you for the name of the domain class.
A domain class represents the core model behind in your application and is typically mapped onto database tables. For more information on domain models in Grails refer to the chapter on
GORM in the user guide.
The exact behaviour of the command depends on the argument you pass. If you don't specify a package (like "org.bookstore" in the example), then the name of the application will be used as the package. So if the application name is "bookstore" and you run
create-domain-class Book
, then the command will create the file
grails-app/domain/bookstore/Book.groovy
. Also, if you don't give your domain class an initial capital letter, it will be capitalized for you. So an argument of "org.bookstore.book" will result in a domain class called
Book
.
If you want the command to default to a different package for domain classes, provide a value for
grails.project.groupId
in the
runtime configuration.
Note that this command is just for convenience and you can also create domain classes in your favourite text editor or IDE if you choose.
Usage:
grails create-domain-class [name]
Fired Events:
CreatedFile
- When the domain class is created