Doctrine 2.返回null而不是相关对象

时间:2015-06-03 11:27:28

标签: php symfony doctrine-orm

我有两个实体:用户和国家/地区。用户拥有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: {  }

0 个答案:

没有答案