使用YAML的Symfony2中的教义映射 [英] Doctrine Mapping in Symfony2 using YAML
问题描述
我已经通过doctrine:generate:entity创建了一个实体,并选择了YAML作为映射格式。
这并没有在../Entity/\"MyEntity\".php上添加任何元数据,这将允许我更新或创建我的模式。
As一个例子,如果我运行
./ app / console doctrine:schema:create
它失败,说:
[RuntimeException ]
BundleMySuperBundle不包含任何映射实体。
我的自动贴图已设置为true。
如果我选择使用注释配置,这不会是一个问题。
我错过了什么吗?有没有额外的步骤,我应该采取?
谢谢你提前,问候,
Ivan
我刚刚看到Doctrine配置初始化代码。我发现是:
- 使用auto_mapping结果为单个默认实体管理器设置各种默认值;它将
类型
的值保留为false - 如果
键入
是false代码查找可能的配置文件的默认目录,一旦找到有效扩展名的文件,它就会按照配置的方式,按照xml
,yml
,php
- 如果没有找到任何那些假设
注释
你还有什么其他的, code> Bundle / Resources / config / doctrine 文件夹?如果是这样,它可能会抛出自动检测。
除此之外,基本上如果你使用了默认值,并且有一些实体类和有效的配置,你应该在没有任何附加配置的情况下工作。你说过auto_mapping是真的,但是你改变了Doctrine配置的其他位吗?
这可能是一个想法,如 Symfony Doctrine文档所述,请从默认配置
doctrine:
dbal:
驱动程序:%database_driver%
#etc
orm:
auto_generate_proxy_classes:%kernel.debug%
auto_mapping:true
显式
doctrine:
dbal:
驱动程序:%database_driver%
#etc
orm:
auto_generate_proxy_classes:%kernel.debug%
auto_mapping:false
映射:
MySuperBundleName:
type:yml
dir:Resources / config / doctrine
I have a question regarding YAML configuration of Doctrine in Symfony2.
I have created an entity via "doctrine:generate:entity", and chose YAML as the mapping format. This didn't add any metadata on ../Entity/"MyEntity".php, which would allow me to update or create my schema.
As an example, if I run
./app/console doctrine:schema:create
it fails, saying:
[RuntimeException]
Bundle "MySuperBundle" does not contain any mapped entities.
My automapping is already set to "true".
If I choose to use annotation config this would not be a problem.
Did I miss something? Are there any extra steps that I should take?
Thank you in advance, regards,
Ivan
I just had a fun time looking at the Doctrine config initialisation code. What I found was:
- Using auto_mapping results in various defaults being set for the single default entity manager; it leaves the
type
value as false - If
type
is false the config code looks into the default directory for likely config files, and as soon as it finds a file of a valid extension it decides that that's the way config is being done, in the orderxml
,yml
,php
- If it doesn't find any of those it assumes
annotation
Do you have anything else at all in the Bundle/Resources/config/doctrine
folder? If so, it might be throwing off the auto-detection.
That aside, basically if you've used defaults, and have some entity classes and valid config, what you're doing should be working without any additional config. You've said "auto_mapping" is true, but have you changed any other bit of Doctrine config?
It might be an idea to try configuring stuff explicitly, e.g. as described in the Symfony Doctrine docs, go from default config
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
to explicit
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
MySuperBundleName:
type: yml
dir: Resources/config/doctrine
这篇关于使用YAML的Symfony2中的教义映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!