#dataSource is null when creating custom repository

4 messages · Page 1 of 1 (latest)

surreal cedar
#

I'm following the instructions here: https://docs.medusajs.com/development/entities/extend-repository

I created a custom repository for a custom entity, and when trying to create a repository like this:

import {dataSource} from "@medusajs/medusa/dist/loaders/database";
import {DraftOrderInvite} from "./draft-order-invite.entity";
export const DraftOrderInviteRepository = dataSource.getRepository(DraftOrderInvite).extend({

I get:

exports.DraftOrderInviteRepository = database_1.dataSource.getRepository(draft_order_invite_entity_1.DraftOrderInvite).extend({
                                                           ^

TypeError: Cannot read properties of undefined (reading 'getRepository')

How do I get access to a non-null/undefined dataSource ?

Learn how to extend a core repository in Medusa to add custom methods.

clear dock
#

hi,
can you access the dataSource definition file ? just to check if you have everything installed properly

surreal cedar
clear dock
#

I've migrated from medex to custom repo/services/entities and didn't had this issue 🤔

also just saw that I have a dataSource.js file at my root directory, maybe it can help ?