Ways to validate a foreign key in Strongloop?

I am faced with a situation where I have a collection of categories and a separate collection of places, with each place having a foreign key that corresponds to a category ID.

You can find the list of categories in categorie.json: http://pastebin.com/ttumKPf9

Similarly, the list of places can be accessed from place.json: http://pastebin.com/J4bdEiUx

In an attempt to validate if a specific category ID exists, I have modified the create method within the place class. This new implementation involves checking if the provided category ID is present in the category list. If it is found, I trigger the upsert method to insert the data into the place. However, the challenge arises when the upsert method recursively calls the create method, causing a deadlock scenario as the data fails to get inserted without invoking the upsert method.

To address this dilemma and successfully verify and insert the data using strongloop, I seek guidance on overcoming this circular call issue within my script.js file:

module.exports = function(app){

 var Place = app.models.place;
 var Categorie = app.models.categorie;

 Place.create = function(data,callback){
  console.log("before searching");

    console.log(data.id);

    Categorie.findById(data.categorieId, function(err, instance){
      console.log("searching")

      if(err){
        throw err;
      }
      if(instance == null){
        new err;
        throw err;
      }

      console.log("Upsert");
      Place.upsert(data, callback);
    });  
 };
};

Answer №1

It's important to revise the remote method instead of focusing on the ORM method.

Alternatively, for those using relational databases, consider implementing foreign key constraints.

Below is an example SQL query involving tables named location and type:

ALTER TABLE location ADD CONSTRAINT Type_locations_fk FOREIGN KEY (typeId) REFERENCES type(id) ON DELETE CASCADE;

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

Received an error while attempting an AJAX GET request to a distinct server hosting a WebAPI

This is my first time encountering an issue with an Ajax request in client-side code. I'm hoping that there's a simple mistake in my code that I'm just overlooking. Just to give some background, when I manually access the URL mentioned below ...

Breaking Long Strings into Multiple Lines Using React Material UI Typography

Currently, I am working with ReactJS and incorporating MaterialUI components library into my project. However, I have encountered a problem with the Typography component. When I input a long text, it overflows its container without breaking onto a new lin ...

Achieving the minimum width of a table column in Material-UI

Currently I am in the process of developing a React website with Material-UI. One query that has come up is whether it's feasible to adjust the column width of a table to perfectly fit the data, along with some extra padding on both ends? Outlined be ...

Is the encoding logical when used in Python for JSON or YAML files?

I attempted to store this dictionary in a json or yaml file: d = {'name': 'María Gómez', 'message': '¡Es una caña atómica!'} with open(file, 'wt', encoding='iso8859-1') as file: json.dump( ...

Guide on integrating an HTML and CSS register form in Django

I have successfully created a responsive register and login using HTML and CSS. Instead of utilizing the standard register form and login provided by Django upon configuration, I want to apply my own custom template. To summarize, while I am familiar with ...

utilizing AJAX to send a POST request and display the response in HTML using Django

I am looking to input a number into a text box and retrieve all the even numbers using ajax with Django. Here is my view: load_template @csrf_exempt def load_template(request): if request.method == 'POST': num1 = request.POST[&a ...

Class with an undefined function call

Currently, I am working with angular2 and TypeScript where I have defined a class. export class Example{ //.../ const self: all = this; functionToCall(){ //.. Do somerthing } mainFunctionCall(){ somepromise.then(x => self.fu ...

Utilize ethereumjs-wallet in your web browser as a standalone module

I am looking to generate a wallet (which includes creating an account address and private key) directly in the browser without the need to connect to a node. It seems that in order to utilize web3.js, a provider (such as Metamask or localnode) needs to be ...

Challenges compiling 'vue-loader' in Webpack caused by '@vue/compiler-sfc' issues

The Challenge Embarking on the development of a new application, we decided to implement a GULP and Webpack pipeline for compiling SCSS, Vue 3, and Typescript files. However, my recent endeavors have been consumed by a perplexing dilemma. Every time I add ...

Updating HTML content based on an active user session using Node.js/Express - A Step-by-Step Guide

I'm struggling to find a way to remove the login/signup buttons once a user has successfully logged in. The issue lies within my header file that needs some modification. <section class="header"> <div class="wrapper"> <nav ...

Interested in learning about conducting a length check validation within specified conditions utilizing the Json Schema Validator?

I have a JSON schema structure that looks like this. { "$schema": "https://json-schema.org/draft/2019-09/schema", "description": "My sample Json", "type": "object", "properties": ...

GdxError: Unable to Load Asset

I'm currently following a tutorial on managing groups of assets, but I am using JSON instead of XML. Even though I believe the asset is loaded, it seems to not be working properly! It would be greatly appreciated if someone could provide a solution. ...

Only a select few expandable elements in the jQuery accordion

How can I create an accordion menu with only a few expandable options? I am looking to include the following items in my menu: Home, Support, Sales, Other The "Home" option is just a link without any sub-menu. Clicking on it should direct users to a spec ...

Combining multiple rows into one using either mysql or lodash was achieved by Node

Currently in my Javascript framework, I am utilizing the Node MySQL library for executing MySQL queries. I encountered an issue with a left join that resulted in multiple rows being returned. This is because the left join generates duplicate rows with diff ...

I am puzzled as to why it is searching for an ID rather than a view

Currently, I am attempting to navigate to a specific route that includes a form, but for some unknown reason, it is searching for an id. Allow me to provide you with my routes, views, and the encountered error. //celebrities routes const express = requir ...

Have Babel transpile configuration files into CommonJS format

I'm having trouble getting my Nuxt app to work with Jest for testing. I have a setupFilesAfterEnv property set with a setupTests.ts file that imports a translation file. The translations file uses ES6 import/export module syntax, but it seems like my ...

The AWS Lambda function utilizing Puppeteer is encountering an issue when trying to switch to a new

My Puppeteer project running in AWS Lambda stopped working since yesterday. I made a small code change, but it keeps getting stuck at the browser's newPage method, even after reverting my changes. I am utilizing the lambda starter kit project from: h ...

Need assistance designing a web interface for managing StrongLoop build and deployment tasks?

I am interested in developing a web user interface for StrongLoop. This UI would allow users to easily build and deploy processes similar to StrongLoop Arc. There are some simple node applications (Web Services) that have not been created using StrongLoop ...

What is the process for generating a submatch for this specific expression?

Trying to extract account status information using a regular expression in the DOM. Here is the specific string from the page: <h3>Status</h3><p>Completed</p> Current regular expression being used: <h3>Status</h3>[&bs ...

Arranging an array in reverse order (starting with underscore) can alter the attributes of the objects within

REVISION: To provide more clarity on the issue, I have recorded a bug using quicktime. Here is the link for your reference: For additional code details, please visit: ORIGINAL INQUIRY: A strange issue has come up while working with Meteor and its depen ...