P
P
Pr00f2020-09-28 18:50:01
symfony
Pr00f, 2020-09-28 18:50:01

How to work with nested objects and forms in Symfony?

I am doing one project, and it has nested objects that need to be edited.
For example, the product class Product, it has a class with characteristics Specs, inside it there are other classes with descriptions of characteristics by categories: Common, Casing, Display... inside these classes are descriptions of parameters, and there can also be nested classes, for example, Specs - Camera - Sensors - an array of Sensor objects
It turns out something like this:

product:
- title
- series
- specs:
  - common:
    - releasedAt
    - ...
  - camera:
    - sensors:
      - [{resolution, aperture, pixelSize}, ...]
    - ...
  - ...
- ...

Then Specs is serialized to json and everything is stored in the
database. Is it correct to use nested forms in such a situation or are there any better solutions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2020-09-28
@Pr00f

Forms do not work well with dynamic content, the best solution would be to move the form to the frontend, and use the serializer + validator + argument-resolver from the backend (see How to filter and map data when implementing an API on Symfony4? )
If you specsalways have the same set of objects and no dynamic parameters, then nested forms may well work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question