外键的Symfony2验证约束

I am building an Restful API where say 'userId' / 'addressId' are POST/PUT (between other fileds) and these fields are foreign keys in the DB.

My question is about Symfony Validation Component as I want to validate if those id's are valid.

This, I think, need to be a 'Doctrine' validator as it will need to query the related tables.

I checked the existing validators and it seems that none of them cover this case, in fact, it is only one Doctrine validator (UniqueEntityValidator)

I am writing a custom validatior at this stage.. but did anyone else find the same issue ? Is it not any standard Symfony/Doctrine validator available for this case?

You do not have to write a custom validator. Symfony has already an object validation functionality. You need to set type option to full name of an entity you want to validate.

# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\User:
    properties:
        address:
            - Type:
                type: AppBundle\Entity\Address