New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to specify entities glob instead of entitiesDir glob #605
Comments
You can do that yourself outside of the ORM, something like this: import globby from 'globby';
const orm = await MikroORM.init({
entities: await (globby('./dist/**/*.entity{.ts,.js}')).map(e => require(e)),
// ...
}); |
After playing around with that approach for a while, I get an error complaining that there are only abstract entities. I think the issue is that the named export needs to be extracted (e.g. extracting |
The whole metadata discovery process happens for this approach too, there is no real difference. This validation error most probably means that you forgot to use |
I definitely am using the
Where the other annotations are part of |
I dont see a reason why that should not work, there are many users of typegraphql here. |
Appreciate the fast responses and for all your work on this library! When I explicitly add |
That error means you have multiple decorators from MikroORM on the same property, like Some users had issues with this error due to watch modes, as at one time there could exist 2 files that exported the same entity. That particular issue is resolved in v4 where the actual path and filename of the entity also matters. |
Great, glad to hear it should work and it is on my end :). I definitely do not have any other annotations from mikroorm on the property. I wonder if somehow my entity is getting processed multiple times or something (maybe related to the |
Looks like this is related to having typeorm in the same project at the same time. Looks like typeorm is reloading the class definition somehow... ugh. |
For anyone else that stumbles across this, was able to get this work by changing the order of imports so Mikro comes before TypeOrm:
instead of
|
Interesting. I guess I could make that validation more precise, now it just checks the global metadata storage wheather something is already defined for that property or not - if that thing is exactly the same type as the parameter, we can skip that validation. Its purpose is really just to avoid multiple different property decorators. |
I am suddenly getting the I am also using TypeGraphql in my project but Mikro and TypeGraphql have coexisted just fine. |
I found my offending code that is triggering this error but it doesn't make any sense to me. In a resolver function I get a Repository instance like:
If I use the entity name as a string (rather than the class itself) the error goes away. The other surprising thing is that this block of code is not even executed at startup, yet somehow it's triggering this error at startup. Any idea why just getting a repository would cause this? |
`entitiesDirs` and `entitiesDirsTs` were removed in favour of `entities` and `entitiesTs`, `entities` will be used as a default for `entitiesTs` (that is used when we detect `ts-node`). `entities` can now contain mixture of paths to directories, globs pointing to entities, or references to the entities or instances of `EntitySchema`. Negative globs are also supported. This basically means that all you need to change is renaming `entitiesDirs` to `entities`. ```typescript MikroORM.init({ entities: ['dist/**/entities', 'dist/**/*.entity.js', FooBar, FooBaz], entitiesTs: ['src/**/entities', 'src/**/*.entity.ts', FooBar, FooBaz], }); ``` BREAKING CHANGE: `entitiesDirs` and `entitiesDirsTs` are removed in favour of `entities` and `entitiesTs`. Closes #605
Hard to say, but keep in mind this is metadata validation error - it is thrown during ORM initialisation, it is definitely not caused by you getting a repository. As said, this should be hopefully fixed in v4, so you could give that a try. Will be releasing new alpha soon. |
`entitiesDirs` and `entitiesDirsTs` were removed in favour of `entities` and `entitiesTs`, `entities` will be used as a default for `entitiesTs` (that is used when we detect `ts-node`). `entities` can now contain mixture of paths to directories, globs pointing to entities, or references to the entities or instances of `EntitySchema`. Negative globs are also supported. This basically means that all you need to change is renaming `entitiesDirs` to `entities`. ```typescript MikroORM.init({ entities: ['dist/**/entities', 'dist/**/*.entity.js', FooBar, FooBaz], entitiesTs: ['src/**/entities', 'src/**/*.entity.ts', FooBar, FooBaz], }); ``` BREAKING CHANGE: `entitiesDirs` and `entitiesDirsTs` are removed in favour of `entities` and `entitiesTs`. Closes #605
That was my understanding, which was why I was so surprised that a line in a function that is only called at runtime was causing the problem. For now I’m just catching this specific error at startup and ignoring it. Obviously a hack. I’ll try the latest 4.0 alpha and see how it behaves. |
4.0 alpha-3 solves my problem |
`entitiesDirs` and `entitiesDirsTs` were removed in favour of `entities` and `entitiesTs`, `entities` will be used as a default for `entitiesTs` (that is used when we detect `ts-node`). `entities` can now contain mixture of paths to directories, globs pointing to entities, or references to the entities or instances of `EntitySchema`. Negative globs are also supported. This basically means that all you need to change is renaming `entitiesDirs` to `entities`. ```typescript MikroORM.init({ entities: ['dist/**/entities', 'dist/**/*.entity.js', FooBar, FooBaz], entitiesTs: ['src/**/entities', 'src/**/*.entity.ts', FooBar, FooBaz], }); ``` BREAKING CHANGE: `entitiesDirs` and `entitiesDirsTs` are removed in favour of `entities` and `entitiesTs`. Closes #605
`entitiesDirs` and `entitiesDirsTs` were removed in favour of `entities` and `entitiesTs`, `entities` will be used as a default for `entitiesTs` (that is used when we detect `ts-node`). `entities` can now contain mixture of paths to directories, globs pointing to entities, or references to the entities or instances of `EntitySchema`. Negative globs are also supported. This basically means that all you need to change is renaming `entitiesDirs` to `entities`. ```typescript MikroORM.init({ entities: ['dist/**/entities', 'dist/**/*.entity.js', FooBar, FooBaz], entitiesTs: ['src/**/entities', 'src/**/*.entity.ts', FooBar, FooBaz], }); ``` BREAKING CHANGE: `entitiesDirs` and `entitiesDirsTs` are removed in favour of `entities` and `entitiesTs`. Closes #605
Closing as implemented in v4 via #618, will be part of |
`entitiesDirs` and `entitiesDirsTs` were removed in favour of `entities` and `entitiesTs`, `entities` will be used as a default for `entitiesTs` (that is used when we detect `ts-node`). `entities` can now contain mixture of paths to directories, globs pointing to entities, or references to the entities or instances of `EntitySchema`. Negative globs are also supported. This basically means that all you need to change is renaming `entitiesDirs` to `entities`. ```typescript MikroORM.init({ entities: ['dist/**/entities', 'dist/**/*.entity.js', FooBar, FooBaz], entitiesTs: ['src/**/entities', 'src/**/*.entity.ts', FooBar, FooBaz], }); ``` BREAKING CHANGE: `entitiesDirs` and `entitiesDirsTs` are removed in favour of `entities` and `entitiesTs`. Closes #605
`entitiesDirs` and `entitiesDirsTs` were removed in favour of `entities` and `entitiesTs`, `entities` will be used as a default for `entitiesTs` (that is used when we detect `ts-node`). `entities` can now contain mixture of paths to directories, globs pointing to entities, or references to the entities or instances of `EntitySchema`. Negative globs are also supported. This basically means that all you need to change is renaming `entitiesDirs` to `entities`. ```typescript MikroORM.init({ entities: ['dist/**/entities', 'dist/**/*.entity.js', FooBar, FooBaz], entitiesTs: ['src/**/entities', 'src/**/*.entity.ts', FooBar, FooBaz], }); ``` BREAKING CHANGE: `entitiesDirs` and `entitiesDirsTs` are removed in favour of `entities` and `entitiesTs`. Closes #605
Is your feature request related to a problem? Please describe.
I am trying to introduce mikro into an existing nestjs project. The entities are all located in separate folders, e.g. '
posts/post.entity.ts
,comments/comment.entity.ts
. There is no parent entities dir and instead I would like to use something like'dist/**/*.entity{.ts,.js}'
.Describe the solution you'd like
Allow the
entities
configuration option to allow for glob paths in addition to the current array of classes. Alternatively, support anentitiesGlob
option.Describe alternatives you've considered
Specifying the entire project as the
entitiesDir
glob. This seems suboptimal.The text was updated successfully, but these errors were encountered: