What is the best way to map two entities in GORM when the primary key of one table is also a foreign key from another table. For ex:
Here is one table:
CREATE TABLE `table_a` (
`a_id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`a_id`)
)
And the pk of this table 'a_id' is referenced by the following table:
CREATE TABLE `table_b` (
`b_id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`b_id`),
KEY `b_id_fk` (`b_id`),
CONSTRAINT `b_id_fk` FOREIGN KEY (`b_id`) REFERENCES `table_a' (`a_id`)
)
How do I map the above two entities in Grails/GORM? The following code will obviously not work since GORM will throw exception saying 'repeated column in mapping for entity'.
class TableB {
TableA tableA
static belongsTo = [TableA]
static mapping = {
id column:"b_id"
version false
tableA column:"b_id"
}
static constraints = {
tableA unique: true
}
}
Note: I'm using grails 1.3.7 but can switch to a newer version if this problem is an issue that has recently been fixed. Please let me know.