Do not allow nested objects to be returned

I am facing an issue with typeorm, where I have a queryBuilder set up like this:

        const projects = await this.conn.getRepository(UserProjectRelations).createQueryBuilder("userProject")
            .innerJoin("userProject.userId", "user", "user.id = :userId", { userId: currentUser.id })
            .leftJoinAndSelect("userProject.projectId", "project")
          

        return await projects.getRawOne();

Why does this query output the following data:

RowDataPacket {
  userProject_id: 67,
  userProject_status: 'Owner',
  userProject_lastUpdate: 2021-03-24T21:13:32.000Z,
  project_id: 21,
  project_name: 'nest',
  project_appName: 'Test123!',
  project_createdAt: 2021-03-24T20:47:40.000Z,
  project_shortDescription: null,
}

Instead of the desired format:

{
    userProject: {
      "id":67,
      "status":"Owner",
      "lastUpdate":"..."
    },
    project: {
      "name":"test",
      "appName":"Test123!",
      "createdAt": "..."
    }
}

I would like to return nested objects without using aliases. Can anyone guide me on how to achieve this using the queryBuilder?

Thank you in advance for any assistance!

Answer №1

Remember to utilize getOne instead of getRawOne.

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

In situations where there may be a duplicate, what alternative can I utilize in place of the id attribute?

I understand that almost any element in the DOM can have an "id" attribute, and I've used it to track each client in a table of clients. Although ids should not be repeated, my rows are assigned unique identifiers based on each person's "clientId ...

Utilizing Class Types in Generics with TypeScript

Struggling to implement a factory method based on the example from the documentation on Using Class Types in Generics, but hitting roadblocks. Here's a simplified version of what I'm attempting: class Animal { legCount = 4; constructor( ...

Bring in a JavaScript file to a Read-Evaluate-Print-Loop (

Currently experimenting on Windows 10 TP build 9926 with nodejs, I am attempting to import a JavaScript file into an active session of nodejs that is operating in the Windows command prompt. This will allow me to call functions from the imported script dir ...

Shifting Vue components within the dom structure?

Whenever I am on a mobile device, I move Vue components higher up in the dom so that I can use absolute positioning without being contained within a relative container. if (this.mobile) { this.$el.parentNode.removeChild(this.$el); document.getElem ...

Guide to verifying the scope of a dynamic array in Javascript

Hey there, I'm currently trying to verify if a value falls within a specific range in a dynamic array. Let's say I have an amount of 3555, and an array of values like [1000,2000,999999]. Typically we would use conditional statements to check for ...

Challenges surrounding asynchronous functionality in React hooks

I've been facing some issues with this code and have resorted to debugging it using console.log(). However, the results I'm getting are not making any sense. Can someone help me identify what's wrong with this code? I noticed that my console ...

Yep, identifying InferType optional attributes

Here's an example of a Yup schema I created to fetch entities known as Parcels: export const FindParcelsParamsSchema = Yup.object({ cursor: Yup.number().optional(), pageSize: Yup.number().positive().integer().optional(), }); All fields are option ...

The issue with property unicode malfunctioning in bootstrap was encountered

I have tried to find an answer for this question and looked into this source but unfortunately, when I copy the code into my project, it doesn't display Unicode characters. section { padding: 60px 0; } section .section-title { color: #0d2d3e ...

PHP is unable to retrieve the formData object sent via ajax

I've been experimenting with sending a formData object to PHP (I'm following a tutorial at this link), but I'm encountering some obstacles. Firstly, I create the formData object and fill it with: var formdata = new FormData(); formdata.appe ...

Processing results after SQLAlchemy queries

When working with SQLAlchemy in Python, I am fetching a dataset from my database : data = session.query(Data).order_by(Data.id.desc()).limit(20) Next, I am loop through the data results in my view : %for item in data: <div class="item"> ...

Preventing redirection post-AJAX call using jQuery

Currently, I am attempting to implement a basic form submission using AJAX to send data to submit.php for database storage. However, upon submission, the page redirects to submit.php instead of staying on the current page. How can I make it submit without ...

Error encountered when attempting to assign a value of the original data type within the Array.reduce function

I am in the process of developing a function that takes a boolean indicator object like this: const fruits = { apple: false, banana: false, orange: false, mango: false, }; Along with an array such as ['apple', 'orange']. The go ...

Using JQuery to Refresh a Div and Trigger an API Call with a Click Event

Currently, I am working on developing a web application that generates random quotes dynamically. Using JQuery, I can successfully make an API call and retrieve JSON data to display a quote. To allow users to fetch new quotes with the click of a button, I ...

What steps should I take to ensure that elements beneath a div are made visible?

I've been working on a unique project to create a website with "hidden text" elements. One of the cool features I've developed is a circular div that follows my mouse cursor and flips all text below it using background-filter in both CSS and Jav ...

Sort through an array using criteria from another array

const items = [[{name:"p2"},{name:"p3"}, {name:"p7"},{name:"p9"},{name:"p1"}],[{name:"p6"}, {name:"p3"},{name:"p7"}, {name:"p9"},{name:"p2"}],[{name:"p ...

`Inconsistent form variable behavior persists despite multiple ajax requests`

I'm in the process of creating a basic email submission form and I've decided to use ajax for it. The issue I'm encountering is that after successfully submitting the form once, any subsequent modifications made to the text within the form a ...

What benefits come from employing jQuery for data storage techniques?

After learning more about jQuery data storage, I have a question. Is there any advantage to using either of these methods: $('#editCity').data('href', "xx"); var a = $('#editCity').data('href'); or $('#edit ...

Convert parameterized lambdas for success and failure into an observable using RxJS

There is a function exported by a library that I am currently using: export function read( urlOrRequest: any, success?: (data: any, response: any) => void, error?: (error: Object) => void, handler?: Handler, httpClient?: Object, ...

Turn off automatic spelling correction and predictive text in a content-editable section

I'm currently working on a cross-browser application using Script#. I've incorporated a contenteditable div where users can input text. However, I am facing an issue with the auto correct/auto completion feature altering the user's text. Co ...

Tips for dynamically loading images as needed

I'm working on a simple image zoom jQuery feature using elevateZoom. You can see a Demo example here. The implementation involves the following code: <img id="zoom_05" src='small_image1.png' data-zoom-image="large_image1.jpg"/> <sc ...