What is the best way to access a field from a different table within a loopback environment

In my Loopback setup, I have two models named Permissions and langs_translate that I am working with in a loop.

Here are the structure of the tables:

Permissions:

--------------------------
| id | icon      | link  |
--------------------------
| 1  | dashboard | home  |
--------------------------
| 2  | users     | users |
--------------------------
| 3  | inbox     | inbox |
--------------------------

langs_translate:

-------------------------------------------------------
| 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  | לוח בקרה   | 
-------------------------------------------------------

I am trying to retrieve the "icon" from the permission table and then connect to the lang_translate table using the key "permission_id" to fetch the field "label". However, the data is only being fetched from the permission table. I am currently using the following code to retrieve the data:

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

Any help on this matter would be greatly appreciated.

Answer №1

Make sure to include include within the filter section:

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

In technical terms, where, include, order, fields, limit, and offset are all different filter types. When using the Angular SDK, it's important to specify them accordingly. Refer to the AngularJS SDK documentation for further information.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Employing data retrieved from an ajax response as a json object

As a newcomer to ajax and Jquery, I am attempting to display my database graphically using c3.js. However, I am facing challenges with utilizing my ajax response in a JavaScript variable. Below is the JSON response from response.php: [{"time":"2014-05-20 ...

When you click on a list of links, a stylish image gallery will appear using fancybox

Can anyone lend a hand with this? I would greatly appreciate any assistance CSS <a id="fancybox" href="javascript:;">Gallery 1</a> <br /> <a id="fancybox" href="javascript:;">Gallery 2</a> <br /> <a id="fancybox" hr ...

Verify whether the SQL query includes a specific text, and if so, substitute it with a different one

Hello, I am a newcomer to MySql and currently using an open-source platform called GLPI that utilizes the MVC method. I have been finding it quite challenging to edit the main code within GLPI, so I am wondering if there is a way for me to modify the sel ...

Transforming an array of JavaScript objects into arrays of key-value pairs based on a specific property with ES6 syntax

Consider an array of objects like this: myArray = [ {name: 'First', parent: 1, delta: 2}, {name: 'Second', parent: 1, delta: 1}, {name: 'Third', parent: 2, delta: 1} ]; The goal is to transform this array into an objec ...

Firebase 9: Access Denied - Realtime Database Security Breach

Currently working on a chat application using Vue3 and Firebase 9, everything is functioning well except for the delete function. An error message appears in the console: @firebase/database: FIREBASE WARNING: set at /message/-MzxBJXezscUw4PbEAys failed: pe ...

What advantages does incorporating "function() 'use strict'" into each individual file provide?

As I dive into revamping an older AngularJS 1.3 project, one striking observation is the consistent pattern of starting each AngularJS code file with: (function () { 'use strict'; angular.module('app').factory('Employees', ...

Alert: '[Vue warning]: Directive "in testing" could not be resolved.'

Currently, I am running unit tests within a Vue 2.0 application using PhantomJS, Karma, Mocha and Chai. Although the tests are passing successfully, I am encountering a warning message with each test indicating an issue like this: ERROR: '[Vue warn ...

Issue with Ionic 2's infinite scroll not triggering method on second scroll attempt

I utilized the ion-tab element to showcase a page (inboxitem) which encompasses ion-list and makes use of ion-infinite-scroll. The following code snippet resides in inboxitem.html <ion-content class="inbox can-swipe-list"> <ion-list> ...

Exploring the versatility of orderBy and filter in handling cross-referenced content across multiple JSON objects

Is there a way to filter and search for the item name when the item details are sourced from another JSON object? Demo: http://codepen.io/anon/pen/GjAxKX While the rest of the filtering and ordering functionalities are functioning correctly, I am struggl ...

Press the mouse button to position the camera close to an element in Three.js

Trying to implement a click to zoom feature with Three.js, I have a canvas and an object loaded in it. When clicking, I want to position the camera near the point of intersection for a zoom effect. Here is my current code, but it's not working as exp ...

Validate the date selected in a dropdown menu using JavaScript

I'm still relatively new to Javascript, just working my way through some tutorials. I have three select boxes in my HTML form as shown below. HTML Form: <table> <form id="enrolment" name="enrolment" onsubmit="return datevalidate();" action ...

Issue with form validation encountered while utilizing the ion-scroll element

I am currently facing challenges with form validation in my Ionic app when using the < ion-scroll> tag. Here is an example of my form: <form ng-show="!success" name="form" role="form" novalidate ng-submit="register()" show-validation> < ...

Tips for updating a value in a React TextField using handleChange function

After clicking a button, I need to dynamically set a value in this textfield: <TextField fullWidth inputProps={{ maxLength: 75 }} key="nomeSocial" id="outlined-basic" label="Nome Social" name="nomeSocial&qu ...

Tips for creating a conditional confirm dialog box in Asp.net using JQuery/Javascript

I have some jQuery and traditional JavaScript mixed together to validate a textbox on my ASP sample page. There is a button, a textbox, and a button_click event in the code behind. When the button is clicked, I want to show an alert if the textbox is empty ...

The step-by-step guide to deactivating server-side JavaScript on MongoDB using a Java application

I am working on a Java web application that interacts with a MongoDB Atlas database for CRUD operations. My goal is to disable server-side JavaScript for my Atlas instance directly from the Java web application itself. After researching, I came across th ...

Issues encountered with Nextjs 13.4 and Next-Auth 4.2 regarding the signIn("credentials", { }); functionality not functioning as expected

When using next-auth credentials in my current project, I encountered an issue with the signIn() function from next-auth/react. It appears that the redirection to the admin page persists regardless of whether the login details are correct or not. {error: n ...

jQuery Does Not Iterate Through Arrays

I am encountering an issue where I am trying to populate an array with images and then pass them to a variable called $image. However, when I attempt to iterate over this array, the same item is being alerted three times. Here is the problematic code snip ...

Navigating to a different page in the app following a document update: a step-by-step guide

I am facing an issue with a page where I am trying to print a specific DIV using the script below... function printReceiptDiv() { var divElements; if (vm.isDLR) { divElements = document.getElementById("DLRreportCont ...

An ultimate guide to mapping a nested array in React.js

Problem: I am struggling to display the entire content of my array. The goal is to render all elements in the array, but so far I can only get one to show up. I have found that including [key] in the object fields is the only way to generate any output. ...

Dynamically load content onto a jQuery Mobile page upon clicking a link

I'm relatively new to working with jQuery Mobile and making AJAX requests. Let me try to explain my issue clearly. Currently, I am developing a mobile project and utilizing the jQuery Mobile auto-complete list, populating it with data from an XML fil ...