Closed Tech-Non closed 1 year ago
Thank you for submitting this issue @Tech-Non , I'll open a PR to explicitly mention that entities should be in the top-level of the models
directory.
Im facing the error EntityMetadataNotFoundError: No metadata for "Post" was found. the post model is created in the top level of models folder only and the migration also worked fine..
later in my custom route.ts i have queried the Posts by
const posts = await datasource .getRepository(Post) .createQueryBuilder('post') .getMany();
it keep on saying that the metadata for the post was not found from the dist folder... im new to this typeorm and pg db help me fix this somebody and i did not created any repositories or services such.
Preliminary Checks
Issue Summary
Hi there, I have been debugging a lot yesterday for an issue with entities and typeorm. Maybe this could be added to the documentation to help other developers find the issue more quickly than I needed.
I had created my entities in a subfolder
src/models/appointments/appointment.ts
and created a migration manually, which worked. When I created the repository and tried to use it in an endpoint, the backend threw a typeorm errorEntityMetadataNotFound: No metadata for "appointment" was found.
.I looked into defining a custom dataSource.js or ormConfig.json, but neither was documented, other than for migrations.
What ultimately solved my problem, was removing the subfolder and putting all entities top-level in the appointments folder.
Maybe I missed some other configuration in the medusa-config.js file, but I looked through all relevant sections in the documentation and didn't see any hints on what I did wrong.
How can this issue be resolved?
What could help resolve this issue for future developers would be:
Either explicitly state that models should be defined top-level without subfolders in the "Medusa Development > Create an Entity" section
Or allow for subfolders to work.
Are you interested in working on this issue?