【发布时间】:2016-10-06 17:13:44
【问题描述】:
我正在尝试在 Loopback 模型中实现子类化,其中我有一个包含公共字段的父表和具有特定字段的父表的子表。
一个实际的例子:
Customer
具有适用于个人和组织的字段的模型
internal_id-
created
Person
只有个人特定字段的模型
first_name-
last_name
Organisation
只有组织特定字段的模型
-
registration_number trade_name
所以基本上Person 继承自Customer 而Organisation 也继承自Customer。
我已按照Extending Models 的指南创建Person 和Organisation 模型 基于Customer 模型
但是,当我在http://0.0.0:3000/persons 创建Person 时,即通过POST,他是在Person 表中创建的,而不是在Customer 表中创建的。
我假设当我基于另一个模型扩展一个模型时,在保存扩展对象模型时,它也会将公共字段保存到父模型中。
似乎并非如此。如何在 Loopback 中实现这一点?
如果这里需要它们是模型 jsons:
customer.json
{
"name": "Organisation",
"plural": "Organisations",
"base": "Customer",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"registration_number": {
"type": "string",
"required": true
},
"trade_name": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
person.json
{
"name": "Person",
"plural": "Persons",
"base": "Customer",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"first_name": {
"type": "string",
"required": true
},
"last_name": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
organisation.json
{
"name": "Organisation",
"plural": "Organisations",
"base": "Customer",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"registration_number": {
"type": "string",
"required": true
},
"trade_name": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
【问题讨论】:
标签: javascript inheritance loopbackjs