Symfony形成大数据集 [英] Symfony form large data set

查看:58
本文介绍了Symfony形成大数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Symfony 4项目,我们需要针对具有许多字段的 surfaces 制作大的 inpection 形式.我们正在寻找一种方法来组织结构和关系并牢记加载速度.

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.

我创建了下面的基本实体示例,仍然很容易将其存储在一个数据库表中.下面的字段是简单的关系或字符串字段,因此InspectionType会很容易.

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;
}

现在是复杂的部分.每个检查可以包含一个或多个表面(ArrayCollection).每个表面都包含不同的字段,请参见下文:

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

  • 屋顶表面(4个字段);
  • Roof surface (4 fields);
  1. 文本类型
  2. 选择类型(单个)
  3. 选择类型(多个)
  4. 日期类型

  • 泄漏(3个字段);
    • Leakage (3 fields);
      1. 文本类型
      2. 图像(关系,OneToMany)
      3. 选择类型(单个)

      • 张力(3个字段);
      • 坡度(3个字段);
      • 屋顶污染(3个字段);
      • 损坏(5个字段);
      • 镇流器(3个字段);
      • (3个字段);
      • UprightWork (4个字段);
      • 扩张叛乱(5个字段);
      • 烟囱(3个字段);
      • 分流箱(3个字段);
      • ... 9个以上+;
        • 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+;
        • 我的问题是如何设置 surfaces 和数据库结构,表面中的每个零件都应像下面这样在其表格上具有与检查的关系(这会创建许多表格,这不好吗?):

          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?):

          • 表感染
          • 表inpection_leakage
          • 表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);
                  ...
              }
          }
          

          是这种方式:)走

          推荐答案

          我建议使用

          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.

          这篇关于Symfony形成大数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆