I encounter an issue when attempting to fetch data from multiple tables

I'm facing an issue with my query

const a = await prisma.$queryRaw`
SELECT r.name as name, r.profileId as profile, o.lastName as lastName
FROM UserSetting r , User o
WHERE r.userId=o.id
`

After running the query, I am getting an error message stating

relation "userSetting" does not exist
, even though it is defined in Prisma's model... I have set up the following relationship:

UserSetting

user   Owner @relation(fields: [userId], references: [id])
userId Int

User

UserSetting UserSetting[]

I'm puzzled about what could be wrong and how can I resolve this issue?

Answer №1

Chances are, you initially created your tables and columns with double-quoted identifiers to preserve uppercase letters. Now you will need to continue using double quotes for them indefinitely:

SELECT r.name, r."profileId" as profile, o."lastName"
FROM   "UserSetting" r, "User" o
WHERE  r."userId" = o.id

Take a look at this for more information:

  • Are PostgreSQL column names case-sensitive?

Also, naming a table "User" may lead to issues since user is a reserved word.

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

What is the best way to reveal CSS files downloaded via npm?

I'm currently working on a Sass/CSS library that I have hosted on npm. I am exploring ways to make it easier for clients to access it, such as using: @import 'library_name' Instead of the less appealing option: @import 'node-modules/ ...

Modify a document that has _id set to :id using Mongoose

I am facing an issue with updating records using Mongoose. The insertion works fine, but the update is not functioning correctly. Here is the code snippet I am working with: app.post('/submit', function(req, res) { var my_visit = new model ...

Why is it that comparing the childNodes of two identical nodes results in false, while comparing their innerHTML yields true?

Currently, I am in the process of developing a simple function in Node.js that compares two DOMs. My goal is to not only identify any differences between them but also pinpoint the exact variance. Interestingly, upon reconstructing identical DOMs using jsd ...

What is the method for parsing FormData() data in nodejs?

When sending a base64 image to the server side using FormData(), the response received may look something like this: {"------WebKitFormBoundaryjJtrF2zdTOFuHmYM\\r\\nContent-Disposition: form-data; name":"\\" ...

How can I omit extra fields when using express-validator?

Currently, I am integrating express-validator into my express application and facing an issue with preventing extra fields from being included in POST requests. The main reason for this restriction is that I pass the value of req.body to my ORM for databas ...

Unable to get custom named local strategies functioning correctly in PassportJS

Recently, I found the need to modify our local strategy in order to accommodate different types of users logging into our website. The current code is as follows: const localLogin = new LocalStrategy(localOptions, function(email, password, done) { // V ...

Using Node.js and MongoDB to filter a sub array within an array of objects

Hello everyone, I currently have an array of objects containing some populated fields. Below is the product schema: import mongoose, { Schema } from 'mongoose'; const productSchema = new mongoose.Schema( { name: String, description: S ...

Improprove the Express Router in a Node.js application

Is there a way to avoid repeating the isUserAuth and isAdminAuth middleware on each endpoint? Can I apply them just once so they work for all routes without having to specify them individually? const { createBranch, getAllBranch, getBranch } = require(&apo ...

Basic server responding with "Error: Page not found"

I am encountering an issue with my server. Whenever I try to access localhost:3000, I receive an error message saying "Cannot GET /". The same problem occurs when I attempt to call /register. Does anyone have any suggestions on how to resolve this? Thank ...

Typescript compiler still processing lib files despite setting 'skipLibCheck' to true

Currently, I am working on a project that involves a monorepo with two workspaces (api and frontEnd). Recently, there was an upgrade from Node V10 to V16, and the migration process is almost complete. While I am able to run it locally, I am facing issues w ...

Implement error handling middleware when utilizing express.Router

I am looking to implement express.Router in my application. I currently have an index file that serves as the server, and a routes file that defines some express routes using express.Router. My goal is to ensure that whenever one of my routes fails, it tr ...

Error message: The module "module" is not found within the Ionic App

After upgrading my Ionic app to the latest version, it compiles correctly. However, upon execution, I encounter the following error: Uncaught Error: Cannot find module "module" at webpackMissingModule (index.js:3) at Object.<anonymous> (inde ...

Having trouble confirming signature with Node.js Crypto library, specifically with key pairs

I have a concise nodejs code snippet where I attempt to sign a string and then verify it using node crypto along with key pairs generated through openssl. Despite trying various methods, the result consistently shows "false" indicating that the signature c ...

Issue encountered: Incompatibility between Mongoose Populate and Array.push()

After reading a different post addressing the same issue, I still couldn't figure out how to implement the solution into my own scenario. The discussion revolved around the topic of node js Array.push() not working using mongoose. In my Mongoose asyn ...

UI-Router is malfunctioning, causing ui-sref to fail in generating the URL

I'm currently working on a project that involves Angular, Express, and UI-router for managing routes. While I've properly configured my $states and included the necessary Angular and UI-router libraries in my HTML file, I am facing an issue wher ...

Stuck in the midst of an AWS Amplify build due to issues

I've created a small web application using Node.js Express, HTML, and CSS. It runs locally with the command "npm start app.js", but I'm facing issues when trying to deploy it as a serverless application on AWS Amplify. Here's the build log ...

The user ID encountered a CastError: Unable to convert the value "64e310ad9d821c557b4f9bc7" (of type string) to an ObjectId for the "userId" path due to a BSONError

When passing the "id" to the hidden input value in EJS, a bson error is encountered. The data is correctly stored in the database, but the error appears in the EJS file. The error occurs in the form.ejs file: form.ejs <!DOCTYPE html> <html lan ...

Convert JSON data into an array of strings that are related to each other

I'm encountering an issue with converting JSON into a string array I must convert a JSON into a string array to dynamically INSERT it into our database, as I need this to work for any type of JSON without prior knowledge of its structure. Here is th ...

What is the best way to organize Node/Express routes based on their type into different files?

My /router/index.js file is becoming too cluttered, and I want to organize my routes by group (user routes, post routes, gear routes) into separate files within /router/routes/. Here's what I currently have set up: app.js var express = require(&apos ...

What steps do I need to take in order to execute `npm update -g npm` on Elastic Beanstalk?

Is there a way to automatically update the NPM version on my Elastic Beanstalk instances as they scale up, without having to manually shell into each one? I need a solution that can handle auto-scaling events and consistently ensure the latest version of ...