An issue occurred while attempting to update or retrieve an Entity with a OneToOne relationship

I am encountering an issue with a GET request. I have two entities, the primary one being Article and the secondary one being ArticleContent. For some reason, when attempting to retrieve a previously created entity, the ArticleContent column returns as null instead of displaying the corresponding id.

Below is the structure of the Article entity:

@Entity('article')
export class Article extends DefaultEntity {

  @Column({ type: 'integer', default: 0 })
  numberOfViews: number;

  @Column({
    type: 'enum',
    enum: ArticleType,
    default: ArticleType.BLOG,
  })
  type: ArticleType;

  @OneToOne(() => ArticleContent, { cascade: true, eager: true })
  @JoinColumn()
  content: ArticleContent;
}

And here is the setup for the ArticleContent entity:

@Entity({ name: 'article_content' })
export class ArticleContent extends DefaultEntity {
  @Column({ type: 'text' })
  title: string;

  @Column({ type: 'text', nullable: true })
  summary: string;

  @Column({ type: 'text', nullable: true })
  description: string;
}

This is how I execute the POST request:

{
  "numberOfViews" : "13", 
  "type:" : "NEWS",
  "content" : [{
      "title" : "TEST"
  }]
}

Upon inspecting the results of the GET request, I notice that the content attribute shows as null.

Answer №1

It appears that the issue stems from utilizing content as type ArticleContent, an object, when a array is being passed to it within the POST request.

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

Notification Alerts within Mobile Apps

Just wanted to share an update on my progress with a mobile application built on Ionic and utilizing Firebase as the database. One of the features I'm currently working on is implementing local notifications. Below are the code snippets: HTML CODE ...

I am facing difficulty in retrieving data from Firestore using Angular

I've been utilizing the AngularFireList provided by @angular/fire/database to retrieve data from firestore. However, despite having data in the firestore, I am unable to fetch any information from it. import { Injectable } from '@angular/core&apo ...

Transforming JavaScript into TypeScript - school project

After researching similar questions and answers, it appears that any valid JavaScript code can also be considered TypeScript? If this is true: const express = require('express'); const bodyParser = require('body-parser'); const ...

The Angular program is receiving significant data from the backend, causing the numbers to be presented in a disorganized manner within an

My Angular 7 application includes a service that fetches data from a WebApi utilizing EntityFramework to retrieve information. The issue arises when numeric fields with more than 18 digits are incorrectly displayed (e.g., the number 23434343434345353453,3 ...

Bidirectional enumeration in TypeScript

I am working with an enum defined as: enum MyEnum { key1 = 'val1' key2 = 'val2' } However, I am unsure how to create a SomeType implementation that fulfills the following requirements: Function: const myFunction = (param: SomeT ...

Transfer information from one table to another while maintaining a reference to the new row

Currently focused on writing a migration script. The main objectives are: To generate another table with all the necessary fields To transfer existing data from the source table to the new dest table. (inserting data into dest, then updating references ...

Retrieve information from a related table using a foreign key in Sequelize and Postgres

Currently, I am in the process of developing a NextJs NodeJs Express application that utilizes Postrges as its database system. In addition, I have set up two servers and incorporated axios to facilitate get and post requests to interact with my API endpoi ...

Encountering a Jest error stating "Function is not defined" while attempting to instantiate a spy in TypeScript

I'm attempting to simulate Cloudwatch in AWS using Jest and typescript, but I'm encountering an issue when trying to create a spy for the Cloudwatch.getMetricStatistics() function. The relevant parts of the app code are as follows: import AWS, { ...

Use an extension module in a Node.js script

I am currently working on integrating babylon.js into my Node.js Angular application. Current Integration Process 1) I have installed the babylon.js npm repository in my project's node modules using npm install --save babylonjs. The image below i ...

Can we guarantee that the key and its corresponding value are both identical strings in Typescript?

Is it possible to enforce the key of a Record to be the same as the inner name value in a large dataset? interface Person<T> { name: T title: string description: string } type People = Record<string, Person<string>> // example dat ...

Using TypeScript generics to create reusable type definitions for reducers

I have a common reducer function that needs to be properly typed. Here's what I have come up with: export interface WithInvalidRows<T extends { [K in keyof T]: InvalidCell[] }> { invalidRows: T; } interface AddPayload<S extends WithInval ...

Angular6 - accessing elements that are not visible on the page

Currently, I am facing a situation where I have a component embedded in my HTML template that needs to remain hidden until a certain condition is met by checking a box. The tricky part is that the condition for setting "showControl" to true relies on calli ...

Employ the coalesce function within a JSON set-returning function

I have a data stored in a slightly unconventional manner, but I need to work with it. The structure of the data is shown in the sample below: create table tickets (ticket_id integer, properties text); insert into tickets values (123,'[{"detail ...

Combine the object with TypeScript

Within my Angular application, the data is structured as follows: forEachArrayOne = [ { id: 1, name: "userOne" }, { id: 2, name: "userTwo" }, { id: 3, name: "userThree" } ] forEachArrayTwo = [ { id: 1, name: "userFour" }, { id: ...

What is the best way to transform a string into emojis using TypeScript or JavaScript?

Looking to convert emoji from string in typescript to display emoji in html. Here is a snippet of the Typescript file: export class Example { emoji:any; function(){ this.emoji = ":joy:" } } In an HTML file, I would like it to dis ...

Looking to develop a dynamic password verification form control?

I am in the process of developing a material password confirmation component that can be seamlessly integrated with Angular Reactive Forms. This will allow the same component to be utilized in both Registration and Password Reset forms. If you would like ...

Utilize a single search query across various tables

Two similar queries are needed for different tables: one for loan_offers table and one for special_offers table for loan_offers @Query( value = "SELECT " + "CAST(o.id AS VARCHAR), o.user_id, " + ...

Tips for efficiently loading data in a sequence using rxjs: within each sequence, there could be multiple calls made

const dates = [{start:'03/06/2020', end: '03/09/2020'}, {start:'03/12/2020', end: '03/03/2021'}, ...] const fetchData = service.get(page = 1, dates[0]) and service.get(page = 2, dates[0]) retrieves the necessary d ...

Supabase encounters various errors during operation

I am encountering some issues while using supabase with TypeScript. Interestingly, I can see the errors in WebStorm, but not in VSCode. Can you provide any assistance? supabase .channel('custom-all-channel') .on( 'postgre ...

What is the best way to specify Next.js Context types in TypeScript?

Can someone help me with defining the types for next js Context and req? Below is the code for the getServerSideProps function- //Server side functions export const getServerSideProps: GetServerSideProps = async (context) => { await getMovies(conte ...