0

I'm working with GORM via Grails 3 and was wondering how domains and their associations look like when output to a MySql database.

I'm really looking for sort of a "cheat sheet" guide. Something that, for example, states:

String                 --> this column data type 

tablePerHierarchy true --> these tables 

hasMany                --> this table/join table 

hasMany & belongsTo    --> ...

I thought this would be a quick Google job, but I haven't turned up anything so far. I also understand that this is based on Hibernate so I've tried searching there as well. I may just render out these tables and note this down myself here, but before I do that does anyone in the community know if such a resource already exists?

IcedDante
  • 6,145
  • 12
  • 57
  • 100

1 Answers1

1

Best of all, just look in your database, it will be easier to see live, use DBMS for this (for example HeidiSQL, Workbench e.t.c.)

This is some examples of default data types ->

1.) Simple data types:

String     -> VARCHAR(255)
Integer    -> BIGINT
BigDecimal -> DOUBLE
Boolean    -> BIT
Date       -> DATETIME

2.) Storage of domains relationships *(To store relations beetwen domains in database gorm adds id (BIGINT) and foreign keys)

a.) hasMany :

  class People { 
      ...
     hasMany = [men : Man]
  }

As there many men in people that is why we store reference key in Man domain. (This mean people table in db will be equivalent to table without hasMany relation)

b.) belongsTo , hasOne

 class Man {                      
    ...                          
    Wife wife                    
    hasOne = [Hobby]             
    belongsTo = [People]         
 }

| wife_id | hoddy_id | people_id |

There will be id (BIGINT) in Man's table : "people_id" with key reference to People table, hasOne is similar to belongsTo and store key reference to Hobby table. (Wife will be simmilar to hasOne = [Wife])

if there will be no hasMany = [men : Man] in People table, there will be additional table: 'man_people'(or smth like that)

| man_id | people_id |

Fore more info about table relations you can find >> Here <<.

By the way you can change default data type in your mapping, for example :

  name type: 'text'

Name will be LongText

P.S. Mb i missed smth, but i hope this will be small "cheat sheet" guide for you.

Community
  • 1
  • 1