Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails GORM composition or hasOne?

I'm a bit confused about the differences between using the static hasOne map and composing objects in domain classes. What are the differences between the two? ie.

class DegreeProgram {

String degreeName
Date programOfStudyApproval
static hasOne = [committee:GraduateCommittee]
}

versus

class DegreeProgram {

String degreeName
Date programOfStudyApproval
GraduateCommittee committee
}

where GraduateCommittee is another GORM domain model class.

like image 799
Visionary Software Solutions Avatar asked Dec 08 '09 19:12

Visionary Software Solutions


People also ask

What is Grails Gorm?

GORM is the data access toolkit used by Grails and provides a rich set of APIs for accessing relational and non-relational data including implementations for Hibernate (SQL), MongoDB, Neo4j, Cassandra, an in-memory ConcurrentHashMap for testing and an automatic GraphQL schema generator.

What is Grails domain class?

A domain class fulfills the M in the Model View Controller (MVC) pattern and represents a persistent entity that is mapped onto an underlying database table. In Grails a domain is a class that lives in the grails-app/domain directory.


1 Answers

A hasOne association should be used in the case where you want to store the foreign key reference in child table instead of the parent in a bidirectional one-to-one.

See this page for an example:

like image 174
Jean Barmash Avatar answered Sep 19 '22 09:09

Jean Barmash