I am trying to start a project using Grails. I have 2 tables, servererver and serverprotocol. The regional server has a one-to-many relationship with serverprotocol (one server for many server protocols). The AreaServer entity class has an assigned primary row key. I manually configured the AreaServer identifier key as an assignable string, and I configured the ServerProtocol class as many in a many-to-one relationship in AreaServer, but when I try to manually configure the foreign key in the AreaServer mapping section, Grails uses the traditional approach. in which it is assumed that the AreaServer foreign key auto-incrementing id with the value "id"
Saves the AreaServer entity class:
class AreaServer { String serverId ... ... static hasMany = [ serverProtocol : ServerProtocol ] static mapping = { serverProtocol lazy:false id name: 'serverId', generator: 'assigned' serverProtocol column: 'server_serverId' }
}
Here is my ServerProtocol entity class:
class ServerProtocol { long dbId .... .... static belongsTo = [ areaServer : AreaServer ] static mapping = { id name: 'dbId' version false }
}
When Grails creates the database and tables, the serverprotocol table has a foreign key called areaServer_id instead of server_serverId, which I configured for this in the AreaServer display section. Setting up a foreign key, as I try to do, should be a standard procedure, as shown in the "table and name" columns in the Grails.org document http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping % 20% 28GORM% 29.html For some reason, changing the name of a foreign key (when a foreign key is nested in a "many" one-to-many relationship table) just doesn't work, as the documentation says it should.
I know that the Grails standard convention should expect each table to have an automatically incrementing primary key called id, which is why the foreign key is called areaServer_id (since AreaServer refers to AreaServer in ServerProtocol) Does anyone know why Grails will not allow me to change the foreign key name manually, as it says, perhaps in the Grails documentation?
Thanks for any help in advance!
source share