Closed jacekjagiello closed 9 years ago
One more thing, my Entity namespace look like this: Acme\Blog\Model\Post
When I move my entity to app
folder and change namespace to just App
, it works!
I've tried to create mappings like:
'mappings' => [
'Acme\Blog\Model\Post => [
'table' => 'task',
'abstract' => false,
],
],
But it doesn't work, still No Metadata Classes to process
@JacekJagiello To use annotations with a custom namespace, you should set: doctrine.php
'metadata' => [
[
'driver' => 'annotation',
'namespace' => 'Acme'
]
],
The default option for metada."array".namespace
is App
@JacekJagiello In my case, instead of running a "full annotation scan", i did this:
'metadata' => [
[
'driver' => 'annotation',
'namespace' => 'App\\Model\\X\\Entity',
'alias' => 'X'
],
[
'driver' => 'annotation',
'namespace' => 'App\\Model\\Y\\Entity',
'alias' => 'Y'
],
[
'driver' => 'annotation',
'namespace' => 'App\\Model\\Z\\Entity',
'alias' => 'Z'
]
],
With this, i reduced the number of files to scan. And i can use this:
// Return the repository for this model
\EntityManager::getRepository('X:Class');
\EntityManager::getRepository('Y:Class');
@josenicomaia Thanks to you I find out something:
'metadata' => [
[
'driver' => 'annotation',
'namespace' => 'App\\Blog\\Model\\Post',
'alias' => 'Post'
]
],
It works! Post
entity was found. But if I have Acme
as a first part of namespace:
'metadata' => [
[
'driver' => 'annotation',
'namespace' => 'Acme\\Blog\\Model\\Post',
'alias' => 'Post'
]
],
It does not work. I still have No Metadata Classes to process
.
Well, I like to keep application on it's own namespace, and I don't want to move it into app/
folder, only to make it recognizable by library. My Acme
namespace is loaded by composer autoloader, I can use it within my code, but Doctrine don't pick it up for some reason. Maybe when I run vendor/bin/doctrine orm:schema:create
my entity isn't loaded jet, or isn't loaded at all?
@JacekJagiello Can you print your files tree?
Yes of course:
Wow. Now i understand. Why are you using app folder? It's supposed to be used for you app development.
@JacekJagiello If you want, I guess you can do using this: doctrine.php
'metadata' => [
[
'driver' => 'annotation',
'namespace' => 'Acme\\Blog\\Model',
'alias' => 'Blog',
'paths' => base_path('src/Acme')
]
],
// Return the repository for this model
\EntityManager::getRepository('Acme\\Blog\\Model\\Post');
// or just:
\EntityManager::getRepository('Blog:Post');
Well, for me, any kind of framework(like Laravel) or library(like thi library) is a "plugin" to the application. Framework, it's not something your app is build upon, it's rather like tool to help you build an app. This is called hexagonal architecture, and it's say you shouldn't mix your application code(application use cases, domain logic and business rules) with your framework. Framework should only "trigger" your application code(via controllers).
So, in the app
folder I will keep Laravel specific code(controllers, service providers, forms) and in src
I will keep my entities, aggregates, value objects, domain events, use cases etc.
@josenicomaia Wow, adding 'paths' => base_path('src/Acme')
solves the problem! :)
I must say that doctrine mapping config is a bit tricky.
Thanks again!
@JacekJagiello Hmmm, I understand. I will learn about this architecture =]
I am grad to help. You're welcome =]
PS.: If this problem is solved, you can close this issue. =]
I guess that we need to document more =P
Hey, I've read #72 because I have the same problem. I set
'metadata' => [ 'driver' => 'annotation' ]
indoctrine.php
, clear cache, but it does not pick up my entities; I gotNo Metadata Classes to process
when I runvendor/bin/doctrine orm:schema:create
Heres my doctrine.php