KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I tried to define one to one relation in 2 different way: 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 mapping. Unfortunately DB has different structure in both cases. Case 1: Case 2: Why once Car and once Engine keeps link to second table. Where is my problem? When I am looking at the code, from DDD perspective, both cases suggest that Car class is more important and Car aggregates Engine. Unfortunately when I look from DB side on case 2 I would rather said that it is opposite - Engine aggregate Car. Of course I can use first approach, but most of publication I saw about grails, present second way for defining relation. Maybe I misunderstood something and I use hasOne in wrong way?
Tags (comma-separated)
Save Edits
Cancel