简体   繁体   English

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

[英]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. 从技术上讲whereincludeorderfieldslimitoffset都是不同类型的滤波器,并具有角SKD应该这样来指定。 Check the AngularJS SDK docs for more info. 查看AngularJS SDK文档以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何通过第一张表从第二张表中获取字段,并使用javascript中的外键? - How can I get field from second table via first table with foreign key from javascript? 如何从另一个文本字段中的一个文本字段中看到文本? - How to see text from one text field in another text field? 从 LoopBack.io 中的 model 的字段中检索 ENUMS? - Retrieving ENUMS from a field of a model in LoopBack.io? 如何将行从第二个表移回初始表? - How to move back the row from second table to initial table? 如何从文档中删除属性-Mongo / Loopback - How to remove a property from document - mongo / loopback 在Loopback中创建模型实例时,如何以编程方式填充字段? - How to populate a field programmatically when a Model instance is created in Loopback? 如何仅用来自 javascript 的数据填充 HTML 表的第二列? - How to fill only the second column of a HTML table with data from javascript? 如何使用javascript从表中获取第二个td值 - How to get second td value from a table using javascript 如何添加自定义标记,然后使用onkeyup将一个输入字段的值显示到第二个输入字段? - How to add the custom tag and then appeand the value from one input field into second input field using onkeyup? 从表中删除第二行 - Remove Second Row From Table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM