You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So i extended the entiy of products, to add a value called "views", this is what i've done:
product model:
import { Column, Entity } from "typeorm"
import {
// alias the core entity to not cause a naming conflict
Product as MedusaProduct,
} from "@medusajs/medusa"
@Entity()
export class Product extends MedusaProduct {
@Column()
views: number
}
import { registerOverriddenValidators } from "@medusajs/medusa"
import {
AdminPostProductsReq as MedusaAdminPostProductsReq,
} from "@medusajs/medusa/dist/api/routes/admin/products/create-product"
import { IsString, IsNumber, IsOptional } from "class-validator"
class AdminPostProductsReq extends MedusaAdminPostProductsReq {
@IsNumber()
views: number
}
registerOverriddenValidators(AdminPostProductsReq)
I am sending a create product request with title, and the views value and its creating the product successfully, however i look at my products table in postgres and its still 0, the default value
help in why its not updating would be appreciated 🙏
note: the product is being added however the logs are saying "error: An error occurred while processing product.created: QueryFailedError: null value in column "title" of relation "product" violates not-null constraint"
The text was updated successfully, but these errors were encountered:
moheldesoqy
changed the title
Custom attribute i added is not updating in the database when sending a request?
Custom attribute after extending entity is not updating in the database when sending a request?
Apr 22, 2024
Hello!
So i extended the entiy of products, to add a value called "views", this is what i've done:
product model:
index.d.ts because i am using typescript:
migration script:
my index.ts code in src/api/index.ts:
I am sending a create product request with title, and the views value and its creating the product successfully, however i look at my products table in postgres and its still 0, the default value
help in why its not updating would be appreciated 🙏
note: the product is being added however the logs are saying "error: An error occurred while processing product.created: QueryFailedError: null value in column "title" of relation "product" violates not-null constraint"
The text was updated successfully, but these errors were encountered: