Grailsが属する使用する



Grails Belongsto Use



Grails3はTo、多対1の関係に属します

参照:http://docs.grails.org/latest/ref/Domain%20Classes/belongsTo.html



オブジェクトの説明:

著者:著者



本:本

本は著者のものです

static belongsTo There are two ways to use it:
method one: static belongsTo = Author //[Domain1,Domain2] There is no reference in this way, the database does not build indexes and foreign keys. Feeling is useless, but it must be specified in many-to-many, otherwise it is abnormal. domain: 
class Author { String name  static constraints = { } }
 
class Book { static belongsTo = Author String title  static constraints = { } }
 Database: Page: ========================================================================================
Method 2:  static belongsTo = [author:Author]//[doamin:Domain1,domain2:Domain2]  Or: Author author static belongsTo = Author This way the database Book table will establish the Author's index and foreign key (author_id) 
doamin: 
class Author { String name  static constraints = { } }
class Book { static belongsTo = [author: Author] String title  static constraints = { } }
database:
page:
The author field is added to the page and can be used for relationship maintenance between book and author.