本文介绍了Grails:外键作为主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我必须说我有一个现有的数据库,它不能被修改(这就是为什么我有这个问题)



我有两种情况,第一种是这样的:
在这种情况下,id(主键)也必须是外键。

  class SbPEstadoComponente {

static mapping = {
table'SB_P_ESTADO_COMPONENTE'
version false
idEstadoComponenteHxPEstado column:'ID_ESTADO_COMPONENTE'
id列:'ID_ESTADO_COMPONENTE'
}

//关系
SbPDemora idEstadoComponenteHxPEstado
字符串可实现的
..
..
..
}

在另一种情况下,表有3列,coluns是3个表的外键。此外,这3列必须是复合主键。



任何想法?建议吗?
非常感谢!

解决方案

在您的子类的映射中,您需要 id composite: ['fkey1','fkey2'] implements Serializable



你做一个 get 你将需要填充所有组合键值


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

这篇关于Grails:外键作为主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:41