Zec*_*eck 5 php symfony doctrine-orm
我是Symfony 2.0和学说的新手.我有不同捆绑的州和客户实体.我只想添加州与客户之间的关系.我编码了州和客户实体.这是我的代码:
/**
* @orm:Entity
*/
class Customer
{
/**
* @orm:Id
* @orm:Column(type="integer")
* @orm:GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @OneToOne(targetEntity="State")
* @JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
}
/**
* @orm:Entity
*/
class State
{
/**
* @orm:Id
* @orm:Column(type="integer")
* @orm:GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @orm:Column(type="string", length="50")
*/
protected $name;
}
Run Code Online (Sandbox Code Playgroud)
我的配置文件:
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
dbname: %database_name%
user: %database_user%
password: %database_password%
orm:
auto_generate_proxy_classes: %kernel.debug%
mappings:
FogCustomerBundle: { type: annotation, dir: Entity/ }
FogMainBundle: { type: annotation, dir: Entity/ }
Run Code Online (Sandbox Code Playgroud)
所以我的问题是当我使用php app/console doctrine:schema:create命令表生成模式时生成.但是关系没有生成/状态列没有在客户表/中发布.为什么?我什么都不知道?我很乐意为每一个建议和帖子.
如果您密切关注Doctrine2文档中的示例,则可能会遇到该问题,因为Symfony2将所有Doctrine2注释放入orm命名空间,您似乎在OneToOne和JoinColumn注释中缺少这些注释.您的$ state属性的代码应如下所示:
/**
* @orm:OneToOne(targetEntity="State")
* @orm:JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
Run Code Online (Sandbox Code Playgroud)
编辑:随着Symfony2 beta2中引入的更改,注释发生了一些变化.注释需要在使用之前导入; 导入Doctrine看起来像这样:
use Doctrine\ORM\Mapping as ORM;
Run Code Online (Sandbox Code Playgroud)
然后新用法如下所示:
/**
* @ORM\OneToOne(targetEntity="State")
* @ORM\JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
Run Code Online (Sandbox Code Playgroud)
有一些讨论进一步的更改注释系统; 如果推出这些更改,我将返回另一个编辑.
| 归档时间: |
|
| 查看次数: |
4772 次 |
| 最近记录: |