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.
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With