我们使用Loopback作为标准RESTFul API。
我有一个脚本,用于根据发现数据库表/结构自动生成模型数据。
我可以为每个表生成架构数据,但我不知道如何为每个表生成关系属性数据,这很重要。
例如,来自servers/models/model-x.json
模型架构的数据:
"validations": [],
"relations": { <<<< definitely need this property to be filled
"members": {
"type": "hasMany",
"model": "user",
"foreignKey": "memberId"
}
},
"acls": [],
"methods": {}
所以我的问题是 - 是否可以从表格和表格中的外键生成此关系数据?或者这个数据太复杂而无法自动生成?
答案 0 :(得分:1)
在发现您设置的架构时associations: true
。
完整代码,遍历所有数据库表并生成模型:Strongloop discovery model still empty