symfony2教义一个完整的例子 [英] symfony2 doctrine onetoone complete example

查看:143
本文介绍了symfony2教义一个完整的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从一个例子中做出一个关系 - http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity

i try make onetoone relation from example - http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity

这是第二次尝试,首先是这里 symfony 2 doctrine relation onetoone

this is second try , first is here symfony 2 doctrine relation onetoone

Adres

<?php
/**
 * Created by PhpStorm.
 * User: grek
 * Date: 18.12.13
 * Time: 16:33
 */

namespace Miejsce\ObiektyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Adres {

    /**
     * @var integer
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     * @ORM\Column(type="string", length=64, nullable=true)
     */
    public $street;


    /**
     * @ORM\OneToOne(targetEntity="Miejsce\ObiektyBundle\Entity\User") */
    private $user;




}

用户

    <?php
/**
 * Created by PhpStorm.
 * User: grek
 * Date: 18.12.13
 * Time: 16:33
 */

namespace Miejsce\ObiektyBundle\Entity;


use Doctrine\ORM\Mapping as ORM;


/**
 * @ORM\Entity
 */
class User {


    /**
     * @var integer
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     * @ORM\Column(type="string", length=64, nullable=true)
     */
    public $name;



    /**
     * @ORM\OneToOne(targetEntity="Miejsce\ObiektyBundle\Entity\Adres")
     */
    private $adres;


}

并拥有:php app / console doctrine :schema:update --force

and have : php app/console doctrine:schema:update --force

php应用程序/控制台原则:schema:update --force

php app/console doctrine:schema:update --force

[ Doctrine\Common\Annotations\AnnotationException]

[语义错误]属性Miejsce\ObiektyBundle\Entity\Adres :: $ user中的注释@ Doctrine\ORM\Mapping没有e

xist,或者不能自动加载。

那么我可以有错误?

[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Doctrine\ORM\Mapping" in property Miejsce\ObiektyBundle\Entity\Adres::$user does not e
xist, or could not be auto-loaded.
So where i can have error ?


  • 错误是在语法 - 我有@ ORM / OneToOne但需要@ ORM\OneToOne现在工作正常! :)

推荐答案

我不知道我是否明白你正在问什么,您的注释设置不正确。

I'm not sure if I understand exactly what you are asking, but your annotations are not setup correctly.

/**
 * @Entity

应该成为

/**
 * @ORM\Entity

/**
 * @Id @Column...

应该成为

/**
 * @ORM\Id
 * @ORM\Column...

对于 @OneToOne 应该是 @ ORM\OneToOne

基本上,您不是正确前缀您的注释。您有使用Doctrine\ORM\Mapping作为ORM; 但是您没有正确使用它。前缀您的注释,这将让你走。

Basically you are not prefixing your annotations correctly. You have use Doctrine\ORM\Mapping as ORM; but you aren't using it properly. Prefix your annotations and that will get you going.

这篇关于symfony2教义一个完整的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆