如何在环回中查看第二个表中的字段?

时间:2021-04-23 12:31:24

I have this 2 models in loopback one called Permissions and the second one called langs_translate.

我在环回中有两个模型,一个叫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". but it only take the fields from the permission table. i'm using this code to take the data:

我想从权限表中看到“图标”,并通过键“permission_id”连接到lang_translate表,并从那些表中取出“label”字段。但它只接受权限表中的字段。我正在使用此代码来获取数据:

$rootScope.menus = Permissions.find({
    include: 
        {"relation": "langsTranslates"},
    filter: {
        where: {
            lang : "heb"
        }
    } 
}, function(data){
    console.log(data);
});

a lot of thanks.

非常感谢。

1 个解决方案

#1


0  

You should specify include under the filter key:

您应该在过滤器键下指定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. Check the AngularJS SDK docs for more info.

从技术上讲,包括,顺序,字段,限制和偏移都是不同类型的过滤器,并且对于角度SKD,应该像这样指定。有关详细信息,请查看AngularJS SDK文档。

#1


0  

You should specify include under the filter key:

您应该在过滤器键下指定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. Check the AngularJS SDK docs for more info.

从技术上讲,包括,顺序,字段,限制和偏移都是不同类型的过滤器,并且对于角度SKD,应该像这样指定。有关详细信息,请查看AngularJS SDK文档。