I have a legacy database with same property to Primary Key and Foreign Key. I'm trying to map it from Grails but I have problems with that. This is my domain class:
class AccommodationPrice {
Integer id
Accommodation accommodation
static mapping = {
table 'alojamiento_precios'
id generator: 'assigned', name: accommodation, type: 'integer'
accommodation column: 'id'
}
}
This is the database table:
CREATE TABLE alojamiento_precios
(
id integer NOT NULL,
CONSTRAINT alojamientoprecios_pkey PRIMARY KEY (id),
CONSTRAINT "FK alojamiento" FOREIGN KEY (id)
REFERENCES alojamiento (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
I read this question Grails: Foreign key as primary key? but it didn't work for me: when I use the composite key, grails asks me for accommodation_id, but I don't have this property in my table, because it is id.