我有以下定义的模型:
学院
{
"name": "academy",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "number",
"required": true
},
"name": {
"type": "string",
"required": true
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
},
"academy_version_id": {
"type": "number",
"required": true
},
"description": {
"type": "string"
}
},
"validations": [],
"relations": {
"versions": {
"type": "hasMany",
"model": "academy_version",
"foreignKey": "academy_id",
"through": "academy_has_versions"
}
},
"acls": [],
"methods": {}
}
academy_version
{
"name": "academy_version",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "number",
"required": true
},
"name": {
"type": "string",
"required": true
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
}
},
"validations": [],
"relations": {
"academies": {
"type": "hasMany",
"model": "academy",
"foreignKey": "academy_version_id",
"through": "academy_has_versions"
}
},
"acls": [],
"methods": {}
}
academy_has_versions
{
"name": "academy_has_versions",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "number",
"required": true
},
"academy_id": {
"type": "number",
"required": true
},
"academy_version_id": {
"type": "number"
}
},
"validations": [],
"relations": {
"academy": {
"type": "belongsTo",
"model": "academy",
"foreignKey": "academy_id"
},
"academy_version": {
"type": "belongsTo",
"model": "academy_version",
"foreignKey": "academy_version_id"
}
},
"acls": [],
"methods": {}
}
现在您可以看到我的academy
模型具有hasMany
至academy_has_versions
当我尝试请求此请求时,我得到以下结果:
如您所见,我得到一个空数组(版本)
这是不正确的,因为我的数据库如下所示:
academy_has_versions
academy_version
那么有人能告诉我我做错了什么吗?
答案 0 :(得分:0)
我找不到错误,但建议您尝试以下操作:
学院
{
"name": "academy",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
},
"description": {
"type": "string"
}
},
"validations": [],
"relations": {
"versions": {
"type": "hasMany",
"model": "academy_version",
"foreignKey": "academy_id",
"through": "academy_has_versions"
}
},
"acls": [],
"methods": {}
}
academy_version
{
"name": "academy_version",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
}
},
"validations": [],
"relations": {
"academies": {
"type": "hasMany",
"model": "academy",
"foreignKey": "academy_version_id",
"through": "academy_has_versions"
}
},
"acls": [],
"methods": {}
}
academy_has_versions
{
"name": "academy_has_versions",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"academy": {
"type": "belongsTo",
"model": "academy",
"foreignKey": "academy_id"
},
"academy_version": {
"type": "belongsTo",
"model": "academy_version",
"foreignKey": "academy_version_id"
}
},
"acls": [],
"methods": {}
}