我有一个问题,在查询结果中缺少相关表的值。
我的查询是:
$em = $this->getDoctrine()
->getManager();
$repo = $em->getRepository("DbBundle:Auto");
$auto = $repo->findAll();
var_dump($auto);
在 vardump 的输出中,缺少字段 hName 和 hCountry 的值... 我希望该原则会自动加载已实现表的值,或者我是否另外进行了连接?
C:Apache24htdocssrcDbBundleControllerDefaultController.php:90:
array (size=3)
0 =>
object(DbBundleEntityAuto)[427]
private 'aId' => int 7
private 'aName' => string 'A5' (length=2)
private 'aPs' => int 190
private 'aHersteller' =>
object(Proxies__CG__DbBundleEntityHersteller)[442]
public '__initializer__' =>
object(Closure)[435]
...
public '__cloner__' =>
object(Closure)[437]
...
public '__isInitialized__' => boolean false
private 'hId' (DbBundleEntityHersteller) => int 1
private 'hName' (DbBundleEntityHersteller) => null
private 'hCountry' (DbBundleEntityHersteller) => null
1 =>
object(DbBundleEntityAuto)[441]
private 'aId' => int 8
private 'aName' => string 'Ibiza' (length=5)
private 'aPs' => int 130
private 'aHersteller' =>
.
.
.ASO
实体:汽车
/**
* Auto
*
* @ORMTable(name="AUTO", uniqueConstraints={@ORMUniqueConstraint(name="const_auto_name", columns={"A_NAME"})}, indexes={@ORMIndex(name="A_HERSTELLER", columns={"A_HERSTELLER"})})
* @ORMEntity
*/
class Auto
{
/**
* @var integer
*
* @ORMColumn(name="A_ID", type="smallint")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $aId;
/**
* @var string
*
* @ORMColumn(name="A_NAME", type="string", length=100, nullable=false)
*/
private $aName;
/**
* @var integer
*
* @ORMColumn(name="A_PS", type="smallint", nullable=true)
*/
private $aPs = '0';
/**
* @var DbBundleEntityHersteller
*
* @ORMManyToOne(targetEntity="DbBundleEntityHersteller")
* @ORMJoinColumns({
* @ORMJoinColumn(name="A_HERSTELLER", referencedColumnName="H_ID", fetch="EAGER")
* })
*/
private $aHersteller;
实体:赫斯特勒
/**
* Hersteller
*
* @ORMTable(name="HERSTELLER", uniqueConstraints={@ORMUniqueConstraint(name="const_hersteller_name", columns={"H_NAME"})})
* @ORMEntity
*/
class Hersteller
{
/**
* @var integer
*
* @ORMColumn(name="H_ID", type="smallint")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $hId;
/**
* @var string
*
* @ORMColumn(name="H_NAME", type="string", length=100, nullable=false)
*/
private $hName;
/**
* @var string
*
* @ORMColumn(name="H_COUNTRY", type="string", length=100, nullable=false)
*/
private $hCountry;
表结构和内容:
您需要在实体存储库中创建自定义方法并选择具有连接关联实体的实体:
namespace AppBundleRepository;
use DoctrineORMEntityRepository;
class AutoRepository extends EntityRepository
{
public function findAll()
{
return $this->createQueryBuilder('a')
->select('a','h');
->join('a.aHersteller', 'h');
->getQuery()
->getResult()
;
}
}