Symfony2 inheritance

I have one parent object that has several child objects that inherit its methods. When it comes time to validate forms, I have no idea how to NOT repeat the restrictions on validating parent fields.

Here is the code:

#validation.yml
Dir\Entity\Parent:
    properties:
        name:
          - NotBlank: {message: 'name.empty'}

Dir\Entity\Child1:
    properties:
        name:
          - NotBlank: {message: 'name.empty'}
        age:
          - NotBlank: {message: 'age.empty'}

Dir\Entity\Child2:
    properties:
        name:
          - NotBlank: {message: 'name.empty'}
        title:
          - NotBlank: {message: 'title.empty'}

As you can see, the name property is returned again and again in the child constraint. Is there a way to include a parent constraint directly in a child constraint, so I don’t have to repeat parental constraint modifications?

Thanks in advance!

+5
source share
1 answer

Sorry, Yokoloko, I forget to give decisions sometimes. Here is what I did:

, , . .

http://symfony.com/doc/master/cookbook/validation/custom_constraint.html

,

0

All Articles