1
協會我後續的實體:與實體(代理錯誤)
- 用戶
- 地址
- 國家
我的用戶連接到地址和地址的國家。我有一個魔術__setter和__getter,當我使用$addresses = $user->__get('addresses');
時,它會檢索我的地址(es)。
轉儲:
array(1) {
[0]=>
object(stdClass)#463 (13) {
["__CLASS__"]=>
string(19) "User\Entity\Address"
["inputFilter"]=>
NULL
["addressid"]=>
int(21)
["street"]=>
string(9) "Lange heg"
["number"]=>
int(19)
["addition"]=>
string(1) "a"
["zipcode"]=>
string(6) "7039CA"
["user"]=>
string(16) "User\Entity\User"
["country"]=>
string(50) "DoctrineORMModule\Proxy\__CG__\User\Entity\Country"
["creator_id"]=>
int(9)
["creation_date"]=>
string(8) "DateTime"
["last_modifier_id"]=>
NULL
["last_modified_date"]=>
NULL
}
}
只有我的國家沒有得到正確的對象(從國家實體)。我協會:
用戶實體:
/**
* Id from user
*
* @ORM\OneToMany(targetEntity="User\Entity\Address", mappedBy="user")
* @var Address
* @access protected
*/
protected $addresses;
地址實體:
/**
* @ORM\ManyToOne(targetEntity="User\Entity\User", inversedBy="addresses")
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id", nullable=false, onDelete="cascade")
* @var User[]
* @access protected
*/
protected $user;
/**
* @ORM\ManyToOne(targetEntity="User\Entity\Country", inversedBy="id")
* @ORM\JoinColumn(name="country_id", referencedColumnName="id", nullable=false)
* @var Country[]
* @access protected
*/
protected $country;
國家實體:
/**
* Id from a country
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\OneToMany(targetEntity="User\Entity\Address", mappedBy="country")
* @var int
* @access protected
*/
protected $id;
在我的地址實體它存儲USER_ID和COUNTRY_ID在數據庫中。我如何從我的用戶中獲得我的國家?沒有返回代理?
是的,很愚蠢。由於「延遲加載」,我不知道它返回了代理。所以他一直都知道這些國家。如果我(如你所說)得到我的國名或其他東西,它只是返回了國家。這個代理來了,因爲我沒有從國家實體得到任何東西。笨。 – Haidy