Doctrine2 - 如何设置oneToOne实体而不是id

That is part of mapping info:

id:
    type: integer
    id: true
    generator:
        strategy: AUTO
ms_id:
    type: string
    unique: true
oneToOne:
    parent:
        targetEntity: Category
        nullable: true

How do I establish a connection with ms_id instead of the id

You can specify the join column parameters with referencedColumnName, see the association mapping document

id:
    type: integer
    id: true
    generator:
        strategy: AUTO
ms_id:
    type: string
    unique: true
oneToOne:
    parent:
        targetEntity: Category
        joinColumn:
          name: category_id
          referencedColumnName: ms_id
        nullable: true