Doctrine and ZF2

梦想与她 提交于 2019-12-13 00:26:58

问题


I am facing trouble using doctrine join. I can't share my code. But I can tell you scenario. Please help me to achieve that.

I have created 2 entity. One User and Language.

User table is having foreign key language_id. and Language is master table with id and code fields.

I want to fetch user with some criteria, such a way it returns Language code from Language table as well.

I write join for that but it returns some full object... Not sure how to fetch corresponding language code from Language table for language_id set in user table

If there is some example you know which can help me then also fine

i have return this in __construct()

 $this->languageObj = new ArrayCollection();

when we print it is gives this

 [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

RECURSION )

I am not able to fetch languageCode from the object


回答1:


You need methods defined in your entity to return the value from the object. It seems like everything is correct you would just need to grab the value from the entity. Here is an example:

$userEntity->getLanguageObj()->getLanguageId();

Your user Entity would need the getLanguageObj method which you can define like this:

public function getLanguageObj() {
     return $this->languageObj;
}

And your Language Entity would also need a getLanguageId method:

public function getLanguageId() {
     return $this->languageId;
}

Hope that helps!



来源:https://stackoverflow.com/questions/20488328/doctrine-and-zf2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!