I tried to define one-to-one relationships in two different ways:
Grails 2.0.3
Case 1:
class Car { String model Engine eng static constraints = { eng unique: true } } class Engine { Double capacity static belongsTo = [car : Car] }
Case 2:
class Car { String model static hasOne = [eng : Engine] static constraints = { eng unique: true } } class Engine { Double capacity static belongsTo = [car : Car] }
looks similar, and both provide one-to-one bidirectional matching. Unfortunately, DB has a different structure in both cases.
Case 1: 
Case 2: 
Why once the car and once the Engine is associated with the second table.
Where is my problem? When I look at the code in terms of DDD, both cases indicate that the Car class is more important, and the Car aggregates Engine. Unfortunately, when I look at the case 2 from the side of the database, I would rather say that it is the other way around - the engine is an aggregate car. Of course, I can use the first approach, but most of the publication I saw about the grail, presenting the second way to determine the relationship. Maybe I misunderstood something and am using hasOne incorrectly?
database grails gorm
mrok
source share