I have a class called Domains with properties – domain, user, start date, due date… I use it once for creating the database with annotations, and once for creating a form in which take place only a few of the properties in the class Domains – for example start and due date (the form is used for update of the information). I create the form in this way:
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('start_date', 'date', array('widget' => 'single_text', 'format' => 'yyyy-MM-dd')); ...
My question is: is it possible to put both kind of annotations – for validation and for the database like this:
/**
* @ORM\Column(type="date", nullable=true)
*/
/**
* @Assert\NotBlank()
* @Assert\Type("\DateTime")
*/
protected $start_date;
If no will it be possible if the one is with annotations and the other with a .yml file? And if yes is it a good practice at all? I did it because a lot of the properties are the same – only the class which shlould be used with the database has more of them and it seems pointless to write two class part of which are identical. I thought about inheritance, too but the problem still stays. Please tell me what will fit the best! 🙂 Thanks in advance!
Yes, you can put both kinds of annotations. Do it like this: