Reputation: 37
Currently I am working with grails
and MySQL
. I create the domain class of user like this:
class User {
String userName
String password
String fullName
String toString(){
"${fullName}"
}
static constraints = {
fullName();
userName(unique:true);
password(password:true);
}
}
While running the app grails will create a table user with structure
id bigint(20)
version bigint(20)
full_name varchar(255)
password varchar(255)
user_name varchar(255)
But I want to create my own table structure like this
user_id int(20)
full_name varchar(255)
password varchar(255)
user_name varchar(255)
and I also want to know the controller and model structure so that I can pass the insert query dynamically .
Can anyone help me with a demo or an example?
Upvotes: 1
Views: 186
Reputation: 75671
This mapping block will remove the "version" column, and change the id column to "user_id" and change the type to what you want:
static mapping = {
id column: 'user_id', sqlType: 'int(20)'
version false
}
Upvotes: 3
Reputation: 7713
Example
class User {
String fname
String postCode
static mapping = {
table 'userTable' //your custom table name if you want
version false //turnoff grails version
id column:'UserId'
firstName column: 'First_Name' //first name column will be like this
postCode type: 'text' //default Grails varchar() but can make to text
//or for id you can use composit key of your chioce for id or even a generator
id composite: ['firstName', 'lastName']
}
}
for more playing on what you are capabale of Refer this link [ORM in GRAILS]
Cheers!!
Upvotes: 1