开发者

Grails: Foreign key as primary key?

first of all i have to say that i have an existing database that it can not be modify (that´s why i am having this problem)

I have two cases, the first one is this: In this case the id (primary key) must be a foreign key as well. The code that i put, it doesn´t work.

class SbPEstadoComponente {

    static mapping = {
         table 'SB_P_ESTADO_COMPONENTE'         
 开发者_开发问答        version false
         idEstadoComponenteHxPEstado column:'ID_ESTADO_COMPONENTE'
     id column:'ID_ESTADO_COMPONENTE'
    }

    // Relation
    SbPDemora idEstadoComponenteHxPEstado
    String facturable
    ..
    ..
    ..
}

In the other case the table has 3 columns, that coluns are foreign key to 3 tables. Also those 3 columns have to be a composite primary key.

Any ideas? sugestions? Thanks a lot !!


In your child class's mapping you need id composite: ['fkey1', 'fkey2'] and implements Serializable

Note that when you do a get you will need to populate all the composite key values

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜