我有一个名为subscription
的模型与另一个模型category
具有hasMany的关系。
如何获取特定订阅的模型。
注意:不是来自API资源管理器
答案 0 :(得分:1)
您应该做的是:
在 common / models / subscription.json 中:
use miloschuman\highcharts\SeriesDataHelper;
$data = $data = [
['Power Electronics', 14.00],
['Introduction to Programming', 3.92],
['Data base Management System', 3.28],
['Object Oriented Analysis and Design', 1.96],
]
'series' => [
[
"name" => "Exam Results",
"data" => new SeriesDataHelper($course_data, ['0:name', '1:y']),
'dataLabels' => [
'enabled' => true,
'rotation' => -90,
'color' => '#FFFFFF',
'align' => 'right',
'format' => '{point.y:.1f}', // one decimal
'y' => 10, // 10 pixels down from the top
'style' => [],
'fontSize' => '13px',
'fontFamily' => 'Verdana, sans-serif',
],
],
],
在 common / models / category.json 中:
{
...
"relations": {
"categories": {
"type": "hasMany",
"model": "Category",
"foreignKey": ""
}
}
}
在REST中(即来自API Explorer的 ):
{
...
"relations": {
"subscription": {
"type": "belongsTo",
"model": "Subscription",
"foreignKey": ""
}
}
}
在代码中(即在 common / models / subscription.js 的remote hook中):
GET /Subscriptions?filter[include]=categories
答案 1 :(得分:0)
好解释。 F3L1X9。 我想在这里添加一些东西- 每当添加hasMany关系时,都会创建一个REST端点,例如
GET /Subscriptions/{id}/categories
这将为您提供具有指定ID的订阅类别