1

我有以下实体:

  • 用户
  • 地址
  • 国家

我的用户连接到地址和地址到国家。我有一个神奇的 __setter 和 __getter,当我使用 时$addresses = $user->__get('addresses');,它会检索我的地址。

倾倒:

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 存储在数据库中。如何从我的用户那里获取我的国家/地区?不返回代理?

4

1 回答 1

1

我真的不确定这一点,但如果你得到国家,代理通常会返回一个国家实体。您是否尝试过实际获取国家/地区并查看您得到什么样的对象?

$addresses[0]->__get('country');
于 2013-04-18T14:15:02.540 回答