想象一个销售订单模型,如下所示:
create table sales_orders(
id int primary key,
order_date date,
customer_party_id int not null references parties,
sales_party_id int not null references parties
);
create table parties (
id int primary key,
type text check (type in 'individuals', 'organizations'),
given_name text,
surname text,
org_name text
);
在这种情况下如何建模 JSData 关系?
显然,我不能这样做:
store.defineMapper("sales_orders", {
relations:{
belongsTo:{
parties:{
foreignKey:"customer_party_id",
localField:"customer_party"
},
parties:{
foreignKey:"sales_party_id",
localField:"sales_party"
}
}
}
});
我可以重命名 belongsTo 字段之一,这适用于读取,但不适用于写入...(使用 JSONAPI 适配器)