Big form collections with Symfony2

145 Views Asked by At

I'm having some trouble with a big form in Symfony2. Let me explain the situation:

A client of me offers one day courses and I'm building an application where participants can sign up for a particular course. The process is simple: a participant logs in, selects a course, selects a date and signs up.

This involves multiple entities:

  1. Course, ~20 required properties, OneToMany with CourseDate
  2. CourseDate, ~1 required property, OneToMany with CoureDateParticipant
  3. CourseDateParticipant, ~20 properties, ManyToOne with Participant

The properties of CourseDateParticipant are almost the same als Course, most of them are only used to override a property of Course in some cases. So most of the times the majority of the CourseDateParticipants properties will be null.

In the backend I'm having one form where the admin can add and edit a whole course at once. The form is similar to the entities I.e. CourseType with a collection of CourseDateType with a collection of CourseDateParticipantType.

Everything is working fine, except with the big courses. A Course can contain up to 50 CourseDate, a CourseDate can contain up to 1000 CourseDateParticipant. Every property has its own field, so with these numbers a form will contain 50*1000*20 = 1.000.000 fields. But, most of these fields will be null.

I already did some Jquery magic to make the UI usable. And when adding a Course only the filled fields will be submitted. When editing only the changed fields get submitted.

But the controller is choking when calling $form->createView() with such big numbers to be prefilled (when editing). Some solutions I'm thinking of:

  • Tell the client to split such big Course in little ones. (not my favorite)
  • Don't render the CourseDateParticpant on initialization, but somehow afterwards if the admin clicks a button. Can be a button to render all, but also a button for each CourseDateParticipant.
  • Remove many properties from CourseDateParticipant and save the exceptions somewhere else.

Do you people have some other/better suggestions?

0

There are 0 best solutions below