0
我们如何为以下场景创建域类。如何将关联列之一用作Grails中表的主键?
CREATE TABLE station
(
store_id integer NOT NULL,
pos_id integer NOT NULL,
CONSTRAINT pos_locations_pk PRIMARY KEY (store_id, pos_id)
)
CREATE TABLE header
(
id serial NOT NULL,
store_id integer NOT NULL,
pos_id integer NOT NULL,
....
CONSTRAINT sales_transactions_pk PRIMARY KEY (id, store_id),
CONSTRAINT sales_transactions_pos_fk FOREIGN KEY (store_id, pos_id)
REFERENCES station (store_id, pos_id)
)
CREATE TABLE line_item
(
id serial NOT NULL,
sale_id bigint NOT NULL,
store_id integer NOT NULL,
.....
CONSTRAINT transaction_lines_pk PRIMARY KEY (id, store_id),
CONSTRAINT transaction_lines_sale_fk FOREIGN KEY (sale_id, store_id)
REFERENCES header (id, store_id)
)
我开始为下面的站域
class Station {
int storeId
int posId
static mapping = {
table "station"
id composite: ['storeId', 'posId']
storeId column: 'store_id'
posId column: 'pos_id'
}
}
和头表
class Header {
int id
Station station
static mapping = {
cache false
version false
table "header"
columns {
station {
column name: 'store_id'
column name: 'pos_id'
}
}
id composite: ['id', 'station.storeId'] // Where I have to use store_id alone from association column to be included as a part of composite key to header table
}
}
和LINE_ITEM表
class LineItem {
int id
Header header
static mapping = {
table "line_item"
columns {
header {
column name: 'sale_id'
column name: 'store_id'
}
}
id composite: ['id', 'header.station.storeId'] // something like this where I have to include store_id along from header table which instead from station table should be included as a part of composite key
}
}
假设这种情况。有许多实体商店,每个商店都有自己的标题表,其中id是按顺序生成的。现在,所有这些标题数据都会被推送到集中式云中,唯一的方法是您可以唯一标识它使用的是id和store_id,因为可以在多个商店中生成相同的id。我可以将作为标题的主键,但是这对于唯一标识具有pos_id的行并没有意义,并且也与LineItem表一样。 –
gowtham
该电台如何适合这张照片?而且,你允许更改数据库模式吗? –
对不起,其实在以前的评论站中没有存储过。是的,我可以编辑架构,但这会对其他许多事情产生巨大影响。我正在寻找建议,无需编辑架构。 – gowtham