這是一個基本問題,我有一個我想引用的關聯對象,但它沒有被實例化。不知道我做錯了什麼。Symfony3 - 不填充的學說關聯對象
我有對象市場和賣方相關的一對多。市場上有很多供應商,供應商只有一個市場。我在加載供應商時希望獲得市場對象。
class Vendor
{
/**
* @ORM\ManyToOne(targetEntity="Expedient\PurchaseBundle\Entity\Market", inversedBy="vendors")
* @ORM\JoinColumn(name="market_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
private $market;
/**
* @var int
*
* @ORM\Column(name="market_id", type="integer", nullable=true)
*/
private $marketId;
...
/**
* Set market
*
* @param \Expedient\PurchaseBundle\Entity\Market $market
*
* @return Market
*/
public function setMarket(\Expedient\PurchaseBundle\Entity\Market $market = null)
{
$this->market = $market;
return $this;
}
/**
* Get market
*
* @return \Expedient\PurchaseBundle\Entity\Market
*/
public function getMarket()
{
return $this->market;
}
當我找到供應商對象時,我看到沒有市場集合。請注意,有一個marketId,但不包含市場對象。
"vendor" => Vendor {#117 ▼
-market: null
-id: "11"
-name: "A-Air Company"
-account: ""
-attn: "Rege Dumm/John Matthews"
-address1: "206 Overlook Drive"
-address2: ""
-city: "Sewickley"
-state: "PA"
-zip: "15143"
-country: "USA"
-phone: "412-741-9420"
-cellPhone: null
-fax: "412-749-8590"
-tag: "A-Air Company"
-active: true
-email: "[email protected]; [email protected]"
-securityAgreement: true
-securityAgreementDate: DateTime {#114 ▶}
-insuranceCert: true
-insuranceCertDate: null
-marketId: 1
}
市場類存在並具有反向設置:
<?php
namespace Expedient\PurchaseBundle\Entity;
/**
* Market
*/
class Market
{
/**
* @var integer
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="Vendor", mappedBy="market")
*/
protected $vendors;
public function __construct()
{
$this->vendors = new ArrayCollection();
}
}
不知道,我可能會與此是想錯了。我是Symfony 3的新手。