This topic contains 16 replies, has 3 voices, and was last updated by Mike Kudelya 6 years, 8 months ago.
-
Topic
-
I have an entity CourseOffering which has a schedule attached (OneToMany of CourseOfferingTime entities). I want to ensure that (a) there is at least one CourseOfferingTime in the collection, and (b) that the start < end on each CourseOfferingTime.
CourseOffering#schedule:
12345678910111213141516171819/*** @var CourseOfferingTime[]|Collection** @ORM\OneToMany(* targetEntity="CourseOfferingTime",* mappedBy="courseOffering",* cascade={"persist"},* orphanRemoval=true* )* @ORM\OrderBy({"start" = "ASC"})* @ConfigField(* defaultValues={* "dataaudit"={* "auditable"=true* }* }* )*/private $schedule;CourseOfferingTime class:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162class CourseOfferingTime implements EntityProperty\DatesAwareInterface{use EntityProperty\DatesAwareTrait;/*** @var int** @ORM\Id* @ORM\Column(type="integer")* @ORM\GeneratedValue*/private $id;/*** @var \DateTime** @ORM\Column(type="datetime")* @Oro\Versioned* @ConfigField(* defaultValues={* "dataaudit"={* "auditable"=true* }* }* )*/private $start;/*** @var \DateTime** @ORM\Column(type="datetime")* @Oro\Versioned* @ConfigField(* defaultValues={* "dataaudit"={* "auditable"=true* }* }* )*/private $end;/*** @var CourseOffering** @ORM\ManyToOne(targetEntity="CourseOffering", inversedBy="groups")* @ORM\JoinColumn(name="course_offering", referencedColumnName="id")* @Oro\Versioned* @ConfigField(* defaultValues={* "dataaudit"={* "auditable"=true* }* }* )*/private $courseOffering;// methods removed}CourseOfferingType::buildForm contents:
12345$builder->add('schedule', 'oro_collection', ['label' => 'my.course.courseoffering.entity.schedule.label','type' => 'my_course_offering_schedule_entry','required' => true,]);CourseOfferingScheduleEntryType::buildForm contents:
123456789101112131415161718$builder->add('start','oro_datetime',array('label' => 'my.course.courseoffering.schedule_entry.entity.start.label','required' => true,'attr' => ['class' => 'start'],));$builder->add('end','oro_datetime',array('label' => 'my.course.courseoffering.schedule_entry.entity.end.label','required' => true,'attr' => ['class' => 'end'],));validation.yml:
12345678910111213141516171819My\Bundle\CourseBundle\Entity\CourseOffering:properties:schedule:- Required:- Count:min: 1minMessage: 'You must specify at least one schedule entry'My\Bundle\CourseBundle\Entity\CourseOfferingTime:properties:start:- Required:- NotBlank: ~- DateTime: ~- Oro\Bundle\CalendarBundle\Validator\Constraints\DateEarlierThan: endend:- Required:- NotBlank: ~- DateTime: ~But none of the constraints are enforced on the client side or on the server side. (eg: if I add an empty CourseOfferingTime to the form I get a DB constraint violation because start is null, whereas I expect to get a form validation error).
Any thoughts or advice on what I’ve missed in setting up the validation?
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.