GORM ID generation and belongsTo association ?
Posted
by fabien-barbier
on Stack Overflow
See other posts from Stack Overflow
or by fabien-barbier
Published on 2010-05-19T22:56:02Z
Indexed on
2010/05/19
23:00 UTC
Read the original article
Hit count: 394
I have two domains :
class CodeSetDetail {
String id
String codeSummaryId
static hasMany = [codes:CodeSummary]
static constraints = {
id(unique:true,blank:false)
}
static mapping = {
version false
id column:'code_set_detail_id', generator: 'assigned'
}
}
and :
class CodeSummary {
String id
String codeClass
String name
String accession
static belongsTo = [codeSetDetail:CodeSetDetail]
static constraints = {
id(unique:true,blank:false)
}
static mapping = {
version false
id column:'code_summary_id', generator: 'assigned'
}
}
I get two tables with columns:
code_set_detail:
code_set_detail_id
code_summary_id
and
code_summary:
code_summary_id
code_set_detail_id (should not exist)
code_class
name
accession
I would like to link code_set_detail table and code_summary table by 'code_summary_id' (and not by 'code_set_detail_id').
Note : 'code_summary_id' is define as column in code_set_detail table, and define as primary key in code_summary table.
To sum-up, I would like define 'code_summary_id' as primary key in code_summary table, and map 'code_summary_id' in code_set_detail table.
How to define a primary key in a table, and also map this key to another table ?
© Stack Overflow or respective owner