Here is an example of how to design Grails domain class with Intellij Idea.For this we need to have blank domain classes. So lets say we created three Domain Classes Company,Book,Author
- To see relationship diagram, Selected Domain Class, and selected tab Domain Class Dependencies.It should look like this
- Lets assume the relation that publication has many books. So I drag mouse from Company to Books. Which invokes a popup asking about relationship between the domains and type and name of the field.
- On Selecting ok from previous popup. Their relation is defined in domain and in diagram. Similarly, lets define
- Book hasMany Authors,
- Authors hasMany Books,
- Book belongsTo Author
- And Diagram looked like this.
- Next Step – Lets add fields to Domain Class all by Intellij Idea’s UI. Select package of domain class and pressshft+ctrl+alt+u. It’ll open package diagram of app.
- Now lets add field name to domain Author. For that we’ll need to select domain author,right click and select fields. It’ll invoke a popup asking details about field.
Similarly we add field name to Author and published on to Book.
- Now lets add a method to named “publishedBefore” to Book which takes a date and return list of books published before that date.For this we need to right click on domain and select method.And it’ll invoke popup asking details.Select create and its done.
This was a simple and easy way to create structure of grails app in Intellij Idea.