Modify the find function within LoopBack

Looking to customize the remote method find in Loopback, I attempted the following approach in my model:

'usestrict';

module.exports = function(Movimenti) {
  Movimenti.once('attached', function(obj) {
    Movimenti.find = function(filter, empty, cb) {
      cb(null, this.find({
        "where": {
          "mov_utente_fk": 2
        }
      }));
    }
  });
};

However, running into an error:

500 Maximum call stack size exceeded

Any assistance with resolving this issue would be greatly appreciated!

Answer №1

To add a specific filter to all queries of your model, you can utilize the scope property in the JSON file where your model is defined:

"scope": {
        "where": {
            "mov_utente_fk" : 2
        }
    }

Referencing the official documentation on Loopback Documentation:

This feature allows you to apply a predefined scope to every query executed by the model's repository

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

Component updates are not working in VueJS

My Vue 1 component requires an object as a prop that needs to be filled by the user. This object has a specific structure with properties and nested inputs. The component is essentially a modal with a table containing necessary inputs. I want to perform v ...

What is causing the initial $.ajax call to fail when sending a data object?

I'm facing an issue with the first $.ajax() call. I need to include URL parameters in the ajax data property. To see this problem in action, check out this fiddle: http://jsfiddle.net/f9e5Y/ Below is the JavaScript code: var urlParameters = { pag ...

Encountering a 'DiscordAPIError: Unknown interaction' error while attempting to share details about a command

As I work on a slash command to deliver information about a specific command when users type /help, I encountered an error when trying to add multiple commands: E:\v13\node_modules\discord.js\src\rest\RequestHandler.js:298 ...

The closest comparison to the For In method in JavaScript in the Apex programming

I am looking for a way in Apex to iterate through all the fields of a list of account objects without having to resort to using JavaScript. Currently, I can achieve this with the following code snippet in JavaScript, but I prefer to keep things within the ...

Changing the URI for the Apollo client instance

Currently, we are using Angular Apollo in one of our projects. The apollo client is being created like this: this.apollo.create({ link: this.httpLink.create({ uri: `${environment.apiBase}/graphql?access_token=${this.tokenService.token}`}), cache: new ...

The script file (.js) isn't showing up on the PHP or HTML webpage

Experiencing a peculiar issue and seeking advice on alternative solutions due to my limited experience in this matter. The Issue: I currently have the following script running smoothly: <script type="text/javascript" id="myscript" src="http://piclau ...

Trigger a click (or selection) on a specific dropdown option using jQuery

I am attempting to initiate a click function upon page load using jQuery on a dropdown option within Chosen, in order to activate a subsequent action. Unfortunately, I have not been successful in getting it to work. I have tried the following methods: jQ ...

Error in table layout caused by asynchronous .get jQuery function

I am facing a challenge in populating a timetable with specific information for each cell from a database. The table is being dynamically refreshed using the following function: function refreshTable() { //Form values var park = $('#Park&apos ...

JavaScript Character Set on the Dynamic Page in Delphi

Within my Delphi application, I am dynamically generating HTML content. Displaying UTF-8 encoded strings in the webpage body is not an issue for me as I use HTMLEscape to encode regular strings (ensuring all strings in the list are properly escaped). The ...

Save geometric shapes data in the SQLite database

How do I go about storing polygon data in an SQLite database? Important: I am utilizing the Cordova plugin. polygon: Point[]; interface Point { x: number; y: number; } https://i.sstatic.net/5EYf2.png ...

Troubles encountered when creating select/drop-down optgroup using jquery

Looking to incorporate the <optgroup> tag into a dropdown with JQuery. The option works as expected, but struggling with getting the option group to function correctly. Here's the HTML setup: <select name="DropDownID" id="DropDownID"> ...

JavaScript multiplying an array in HTML

Snippet of HTML code <input name="productCode[]" value="" class="tInput" id="productCode" tabindex="1"/> </td> <input name="productDesc[]" value="" class="tInput" id="productDesc" readonly="readonly" /></td> <input name="pr ...

Updating objects in Angular 8 while excluding the current index: a guide

this.DynamicData = { "items": [ { "item": "example", "description": "example" }, { "item": "aa", "description": "bb" }, ...

Why does my loading screen appear again when I submit the form and refresh the page?

I've been working on setting up a login page and was able to create a loading screen that fades away once the page has finished loading. $(window).on("load",function(){ setTimeout(function() { $(".lo ...

Validation of forms on the client side using Angular in a Rails application

I'm facing an issue with implementing client-side validations for a devise registration form using Angular. Although I am able to add the "invalid" class to the fields as expected, I am struggling to get any output when using ng-show. There are no oth ...

Nodejs Websocket integration with the Firefox browser

Currently, I am utilizing Aurora 17 along with Chrome 22 and Firefox 16 in order to develop a basic chat application. My server-side technology is Node 0.8.9. The issue I am experiencing pertains specifically to Firefox, as it fails to establish a connect ...

Switching Between Background Images in Angular

Looking to change the background-image of an element upon clicking it. Currently, this is what's in place: <div class="item-center text-center" toggle-class="active cable"> <div class="quiz-background"></div> <p class="size ...

Pressing the Enter key triggers the addNewRow function using JavaScript

Here is the code snippet I am currently working with: $(document).on('keypress', ".addNewRow", function(e){ var keyCode = e.which ? e.which : e.keyCode; if(keyCode == 9 ) addNewRow(); }); This code adds a new row to a table when the "Ta ...

The image you are looking for at './expo-asset/assets/${your_img_path}' was not located within React Native or Expo

My current project is an expo ejected react native project and I'm encountering the error message [native] Could not find image on path The file path in question: 'file:///var/mobile/Containers/Data/Application/..../Library/Application%20Support ...

Incorporating Local Storage into a To-Do List Application

I followed a tutorial from w3schools to create a custom task list, tweaking the code to fit my requirements. My goal is to ensure that when I click the save button in the toolbar at the top and then refresh the page, the added tasks are preserved. I&apos ...