学说2 - ORM ZF2

时间:2013-12-10 10:12:26

标签: orm doctrine-orm zend-framework2

我有实体和适当的映射。 PFB

/**
 * User
 *
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User{

     /**
     * @ORM\OneToOne(targetEntity="Language", mappedBy="languageCode2")
     **/
    private $languageObj;

    function __construct(){

       $this->languageObj = new ArrayCollection();
    }

}

/**
 * Language
 *
 * @ORM\Entity
 * @ORM\Table(name="language")
 */
class Language
{

 /**
    * @ORM\OneToOne(targetEntity="User", inversedBy="languageObj")
    * @ORM\JoinColumn(name="language_id", referencedColumnName="language_id")
    */
    private $languageCode2;


    public function __construct()
    {
         $this->languageCode2 = new ArrayCollection();
        }
}

当我打印时它在下面给出

[languageObj:User:private] => Common\User\Entity\Language Object
            (
                [languageId:Language:private] => 1
                [languageCode:Language:private] => en
                [languageName:Language:private] => English
                [languageCode2:Language:private] => User Object

我面临的问题是,我无法从语言对象

中获取languageCode

为此,我在__construct() User课程的$this->lc = $this->languageObj->first(); 中写了以下内容

getCode()

AND

$ this-> lc = $ this-> languageObj-> getCode();

Language$this->languageCode类中的方法,返回{{1}}变量

0 个答案:

没有答案