Add even when object is null?

Hi guys,
I have some issues with my schema:
export const userItems = pgTable("userItem", {
        product_id: serial("product_id").notNull(),
        user_id: text("user_id").notNull(),
        quantity: integer("quantity")
    },
    (userItems) => ({
            compoundKey: primaryKey(userItems.product_id, userItems.user_id),
        }
    )
)

export const userItemsRelations = relations(userItems, ({one}) => ({
    product: one(products, {
        fields: [userItems.product_id],
        references: [products.id]
    }),

    user: one(users, {
        fields: [userItems.user_id],
        references: [users.id]
    }),
}))

You can see a small part of my schema.

In fact, I can add a user item even when the product_id, that refers to my product id, doesn't exist.
How can I tackle this issue ? I should check before the insert in my request?
Thanks
Was this page helpful?