Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

php - Symfony form large data set

For a Symfony 4 project we need to make a large inpection form about surfaces with many fields. We're looking for the approach how to organize the structure and relationships and keep load speed in mind.

I've created the basic entity example below, which is still simple to be stored in one database table. The fields below are simple relations or string fields so a InspectionType would be easy.

class Inspection
{
    /** @var string */
    protected $projectName;

    /** @var string */
    protected $projectPlace;

    /** @var User */
    protected $inpector;

    /** @var Customer */
    protected $customer;

    /** @var string */
    protected $conclusion;

    /** @var string */
    protected $advice;

    // Complex part
    
    /** @var Collection */
    protected $surfaces;
}

Now for the complex part. Each inspection could contain one or more surfaces (ArrayCollection). Each surface consists of different fields, see below:

  • Roof surface (4 fields);
  1. text type
  2. choice type (single)
  3. choice type (multiple)
  4. date type
  • Leakage (3 fields);
  1. text type
  2. images (relation, OneToMany)
  3. choice type (single)
  • Tension (3 fields);
  • Slope (3 fields);
  • Roof Pollution (3 fields);
  • Damage (5 fields);
  • Ballast (3 fields);
  • Eaves (3 fields);
  • UprightWork (4 fields);
  • Dilation Rebellion (5 fields);
  • Chimney (3 fields);
  • Shunt Box (3 fields);
  • ... 9 more+;

My question how to setup surfaces and database structure, should each part in a surface have its on table like below with a relation back to inspection (this would create many tables, is this bad?):

  • table inpection
  • table inpection_leakage
  • table inpection_tension
  • ...

I was thinking to create an Embed Collection Form like below

class InspectionType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // ...

        $builder->add('surfaces', CollectionType::class, [
            'entry_type' => SurfaceType::class,
            'entry_options' => ['label' => false],
        ]);
    }
}

class SurfaceType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('leakage', LeakageTyoe::class);
        $builder->add('tension', Tension::class);
        $builder->add('slope', Slope::class);
        ...
    }
}

Is this the way :) to go

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would suggest to use a discriminator/inheritance map for your surfaces entity, with a single_table strategy. This gives you the speed and flexibility you need.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...