我有两个实体:用户和国家/地区。用户拥有Country的外键。 User.country_id = Country.id。当我以这种方式访问用户实体时: `
$user = $this->em
->getRepository('ItezoItezoBundle:User')
->find($userId);
` 我得到country = NULL。这是$ user的var_dump:
object(\Entity\User)#327 (22) {
["id":"\Entity\User":private]=>
int(2)
["regCountry":"\Entity\User":private]=>
NULL
["answerForSecurityQuestion":"\Entity\User":private]=>
NULL
["answerForNewSecurityQuestion":"\Entity\User":private]=>
NULL
}
映射文件:
type: entity
table: user
indexes:
fk_users_1_idx:
columns:
- country_id
fk_users_2_idx:
columns:
- reg_country_id
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
manyToOne:
country:
targetEntity: Country
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
country_id:
referencedColumnName: id
orphanRemoval: false
regCountry:
targetEntity: Country
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
reg_country_id:
referencedColumnName: id
orphanRemoval: false
lifecycleCallbacks: { }
type: entity
table: country
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
cc:
type: string
nullable: false
length: 5
fixed: false
comment: ''
name:
type: string
nullable: false
length: 255
fixed: false
comment: ''
shortName:
type: string
nullable: false
length: 20
fixed: false
comment: ''
column: short_name
flagImgUrl:
type: string
nullable: false
length: 255
fixed: false
comment: ''
column: flag_img_url
lifecycleCallbacks: { }