[英]How to see field from second table in loopback?
I have this 2 models in loopback one called Permissions and the second one called langs_translate. 我在环回中有这2个模型,一个称为Permissions,第二个称为langs_translate。
The tables look like this: 这些表如下所示:
Prmission: Prmission:
--------------------------
| id | icon | link |
--------------------------
| 1 | dashboard | home |
--------------------------
| 2 | users | users |
--------------------------
| 3 | inbox | inbox |
--------------------------
...
"relations": {
"langsTranslates": {
"type": "hasMany",
"model": "langs_translates",
"foreignKey": "permission_id"
}
},
....
lang_tranlate lang_tranlate
-------------------------------------------------------
| id | label | permission_id | lang | translate |
-------------------------------------------------------
| 1 | HOME_TXT | 1 | eng | Dashboard |
-------------------------------------------------------
| 2 | USERS_TXT | 2 | eng | Users |
-------------------------------------------------------
| 3 | INBOX_TXT | 3 | eng | Inbox |
-------------------------------------------------------
| 4 | USERS_TXT | 2 | heb | לקוחות |
-------------------------------------------------------
| 5 | INBOX_TXT | 3 | heb | הודעות |
-------------------------------------------------------
| 6 | HOME_TXT | 1 | heb | לוח בקרה |
-------------------------------------------------------
...
"relations": {
"permissions": {
"type": "belongsTo",
"model": "permissions",
"foreignKey": "permission_id"
}
},
...
I want to see the "icon" from the permission table and connect to lang_translate table by the key "permission_id" and take from those table the field "label". 我想从权限表中看到“图标”,并通过键“ permission_id”连接到lang_translate表,并从这些表中获取字段“ label”。 but it only take the fields from the permission table. 但它仅占用权限表中的字段。 i'm using this code to take the data: 我正在使用此代码来获取数据:
$rootScope.menus = Permissions.find({
include:
{"relation": "langsTranslates"},
filter: {
where: {
lang : "heb"
}
}
}, function(data){
console.log(data);
});
a lot of thanks. 非常感谢。
You should specify include
under the filter
key: 您应该在filter
键下指定include
:
Permissions.find({
filter: {
where: { lang : "heb" },
include: {"relation": "langsTranslates"},
}
}, function(data){
console.log(data);
});
Technically where
, include
, order
, fields
, limit
and offset
are all different types of filters, and with angular SKD it should be specified like that. 从技术上讲where
, include
, order
, fields
, limit
和offset
都是不同类型的滤波器,并具有角SKD应该这样来指定。 Check the AngularJS SDK docs for more info. 查看AngularJS SDK文档以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.